Our great sponsors
-
Create a mock of the Repository that you're testing, it's the simplest one and the more cumbersome one, you can use a library like jest-create-mock-instance or jest-mock-extended or ts-auto-mock to create a mock from typings, but you're responsible to implement how it supposes to work.
-
jest-mock-extended
Type safe mocking extensions for Jest https://www.npmjs.com/package/jest-mock-extended
Create a mock of the Repository that you're testing, it's the simplest one and the more cumbersome one, you can use a library like jest-create-mock-instance or jest-mock-extended or ts-auto-mock to create a mock from typings, but you're responsible to implement how it supposes to work.
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
-
Example: https://github.com/leosuncin/nest-api-example/blob/88cf73a2189c8556c703a2f8b4ff21970d7ffab4/src/blog/services/comment.service.spec.ts
-
In my case, I use TypeORM with PostgreSQL, and there's pg-mem to run an instance in memory, it supports most of the common functionality of PostgreSQL but you will need to do some adjustment to your code to be within the limits.
-
Other in-memory alternatives for PostgreSQL embedded-postgres (I haven't tried it yet) postgres-wasm (currently it only runs in the browser).
-
In the case of MongoDB there's jest-mongodb that use mongodb-memory-server; for other DBMS, I don't know if it's possible to run an instance in memory.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
mongodb-memory-server
Spinning up mongod in memory for fast tests. If you run tests in parallel this lib helps to spin up dedicated mongodb servers for every test file in MacOS, *nix, Windows or CI environments (in most cases with zero-config).
In the case of MongoDB there's jest-mongodb that use mongodb-memory-server; for other DBMS, I don't know if it's possible to run an instance in memory.
-
testcontainers-node
Testcontainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
You can always run a container with a real DB that you can destroy and the re-create whenever you please, use something like docker-compose or testcontainers to run them. Be aware this can be slow and require more resources to implement.
-
Example: https://github.com/leosuncin/nest-api-example/blob/master/test/auth.e2e-spec.ts https://github.com/leosuncin/nest-api-example/blob/master/docker-compose.yml https://github.com/leosuncin/nest-auth-example/blob/master/test/todo.e2e-spec.ts
Related posts
- Having issues with passing a Typed object to a func... TS isn't warning when properties of said arg are the wrong type
- Trouble Building Chrome Extension to Get News Article Content
- Running Jest for Typescript CLI - unexpected token at import
- Lab 8: TESTING !!!!
- Help me understand the state of TS mocking ecosystem