
Security News
curl Shuts Down Bug Bounty Program After Flood of AI Slop Reports
A surge of AI-generated vulnerability reports has pushed open source maintainers to rethink bug bounties and tighten security disclosure processes.
This is a mock for PrismaClient. It actually reads your schema.prisma and generate models based on it.
It perfectly simulates Prisma's API and store everything in-memory for fast, isolated, and retry-able unit tests.
It's heavily tested, by comparing the mocked query results with real results from prisma. Tested environments include MySQL, PostgreSQL and MongoDB.
This library can also be used as an in-memory implementation of Prisma, for reasons such as prototyping, but that's not its primary goal.
After setting up Prisma:
yarn
$ yarn add -D prismock
npm
$ npm add --save-dev prismock
There are a few options here, depending on your application architecture.
You can create a __mocks__ directory at the root of your project, with a sub-directory named @prisma. Inside the @prisma directory, create a client.js file (or client.ts for TypeScript).
Inside the client file, you can re-export the @prisma/client module, and replace PrismaClient by PrismockClient:
import { PrismockClient } from 'prismock';
export * from '@prisma/client';
export { PrismockClient as PrismaClient };
That's it, prisma will be mocked in all your tests (tested with Jest & ViTest)
You can mock the PrismaClient directly in your test, or setupTests (Example):
jest.mock('@prisma/client', () => {
return {
...jest.requireActual('@prisma/client'),
PrismaClient: jest.requireActual('prismock').PrismockClient,
};
});
You can instantiate a PrismockClient directly and use it in your test, or pass it to a test version of your app.
import { PrismockClient } from 'prismock';
import { PrismaService } from './prisma.service';
const prismock = new PrismockClient();
const app = createApp(prismock);
Then, you will be able to write your tests as if your app was using an in-memory Prisma client.
If you are using a custom client path, you need the createPrismock method.
See use with decimal.js.
Two additional functions are returned compared to the PrismaClient, getData, and reset. In some edge-case, we need to directly access, or reset, the data store management by prismock.
Most of the time, you won't need it in your test, but keep in mind they exist
const prismock = new PrismockClient();
prismock.getData(); // { user: [] }
const prismock = new PrismockClient();
prismock.reset(); // State of prismock back to its original
| Feature | State |
|---|---|
| findUnique | β |
| findFirst | β |
| findMany | β |
| create | β |
| createMany | β |
| delete | β |
| deleteMany | β |
| update | β |
| updateMany | β |
| upsert | β |
| count | β |
| aggregate | β |
| groupBy | π¬ note |
| Feature | State |
|---|---|
| distinct | β |
| include | β |
| where | β |
| select | β |
| orderBy (Partial) | β |
| select + count | β |
| Feature | State |
|---|---|
| create | β |
| createMany | β |
| update | β |
| updateMany | β |
| connect | β |
| connectOrCreate | β |
| upsert | β |
| set | β |
| disconnect | β |
| delete | β |
| Feature | State |
|---|---|
| equals | β |
| gt | β |
| gte | β |
| lt | β |
| lte | β |
| not | β |
| in | β |
| notIn | β |
| contains | β |
| startWith | β |
| endsWith | β |
| AND | β |
| OR | β |
| NOT | β |
| mode | β |
| search | β |
| Feature | State |
|---|---|
| some | β |
| every | β |
| none | β |
| is | β |
| Feature | State |
|---|---|
| set | β |
| push | β |
| Feature | State |
|---|---|
| has | β |
| hasEvery | β |
| hasSome | β |
| isEmpty | β |
| equals | β |
| Feature | State |
|---|---|
| increment | β |
| decrement | β |
| multiply | β |
| divide | β |
| set | β |
| Feature | State |
|---|---|
| path | β |
| string_contains | β |
| string_starts_withn | β |
| string_ends_with | β |
| array_contains | β |
| array_starts_with | β |
| array_ends_with | β |
| Feature | State |
|---|---|
| @@id | β |
| @default | β |
| @relation | β |
| @unique | β |
| @@unique | β |
| @updatedAt | β |
| Feature | State |
|---|---|
| autoincrement() | β |
| now() | β |
| uuid() | β |
| auto() | β |
| cuid() | β |
| dbgenerated | β |
| Feature | State |
|---|---|
| onDelete (SetNull, Cascade) | β |
| onDelete (Restrict, NoAction, SetDefault)() | β |
| onUpdate | β |
Basic groupBy queries are supported, including having and orderBy. skip, take, and cursor are not yet supported.
_count for mongodb$runCommandRaw, findRaw, aggregateRaw)While Prisma is amazing, its unit testing section is treated as optional. On the other hand, it should be a priority for developers to write tests.
As I love Prisma, I decided to create this package, in order to keep using it on real-world projects.
I'm also a teacher and believe it's mandatory for students to learn about testing. I needed a similar solution for my backend course, so I created my own.
I'm personally using this library in my day-to-day activities, and add features or fix bugs depending on my needs.
If you need unsupported features or discover unwanted behaviors, feel free to open an issue, I'll take care of it.
Inspired by prisma-mock.
FAQs
A mock for PrismaClient, dedicated to unit testing.
The npm package prismock receives a total of 20,970 weekly downloads. As such, prismock popularity was classified as popular.
We found that prismock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A surge of AI-generated vulnerability reports has pushed open source maintainers to rethink bug bounties and tighten security disclosure processes.

Product
Scan results now load faster and remain consistent over time, with stable URLs and on-demand rescans for fresh security data.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.