Never hit the database again while testing.

Mock all database calls in your app so your code never hits the database again.

index.test.js
package.json
describe("test suites", () => {
it("test", async () => {
const typeorm = new MockTypeORM();
typeorm.onMock(User).toReturn([], "find")
// other code here ...
})
})

Introduction

Getting started

Learn how to get started with Mock TypeORM to mock your TypeORM calls.

Installation

Step-by-step guides to setting up your system and installing the library.

Core concepts

Learn how the internals work.

API reference

Learn to easily customize and modify mocking to fit your needs.

Community & Support

How to contribute to this project or submit an issue.


Inspiration

In the last couple of months, I have been working extensively with TypeORM and built many projects using this ORM. Setting up a test database for my unit tests was quite challenging. To overcome this, I mocked TypeORM methods to avoid interacting with a real database. However, I found myself copying the same mock code into every new project repeatedly.

To streamline this process and help others facing the same issue, I decided to create a package. Initially, I mocked all the TypeORM code using Vitest, but that only worked in the Vitest environment. Since many developers use different testing frameworks such as Jest, Mocha, etc., I needed a more versatile solution. Hence, I used Sinon for mocking TypeORM, which is compatible with various testing frameworks. Although Sinon is excellent, I still have a soft spot for Vitest.

I have put a lot of effort and time into building this package. If you find it useful, please consider sponsoring my project. Thanks. Enough talk, let's get started.

Submit an Issue

If you notice that a specific feature or method isn't mocked yet, or if you encounter any issues while using the package, please submit an issue on GitHub. Providing detailed information about the missing feature or the issue you're facing will help us understand your needs better.

By submitting an issue, you contribute to the improvement of this package. Not only will I be able to look into it, but other contributors from the community might also step in to help add the required features or resolve the problem. Collaboration is key to making this package more robust and useful for everyone.

To submit an issue, follow these steps:

  1. Visit the GitHub repository for Mock TypeORM.
  2. Click on the "Issues" tab.
  3. Click the "New issue" button.
  4. Provide a clear and descriptive title for your issue.
  5. In the description, include as much detail as possible. If it's a missing feature, describe the feature and how you expect it to work. If it's a bug, describe the steps to reproduce the issue, your environment, and any relevant code snippets or error messages.

Your contributions are greatly appreciated. Thank you for helping improve Mock TypeORM!