![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
prisma-mock
Advanced tools
This is a mock of the Prisma API intended for unit testing. All the data is stored in memory.
The library jest-mock-extended
is used, which means that if functionality you need is not implemented yet, you can mock it yourself.
Simple example how to create a prisma mock instance:
import createPrismaMock from "prisma-mock"
let client
beforeEach(() => {
client = createPrismaMock()
})
An example how to mock a global prisma instance, as the default export in a "db" directory (like blitzjs):
import createPrismaMock from "prisma-mock"
import { mockDeep, mockReset } from "jest-mock-extended"
jest.mock("db", () => ({
__esModule: true,
...jest.requireActual("db"),
default: mockDeep(),
}))
import db, { Prisma } from "db"
beforeEach(() => {
mockReset(db)
createPrismaMock({}, Prisma.dmmf.datamodel)
})
createPrismaMock(
data: PrismaMockData<P> = {},
datamodel?: Prisma.DMMF.Datamodel,
client = mockDeep<P>(),
options: {
caseInsensitive?: boolean
} = {}
): Promise<P>
data
You can optionally start up a pre-filled db, by passing in an object containing keys for tables, and values as arrays of objects (though using create
is preferred). Example:
createPrismaMock({
user: [
{
id: 1,
name: "John Doe",
accountId: 1,
},
],
account: [
{
id: 1,
name: "Company",
},
],
})
datamodel
The datamodel of the prisma client, value of Prisma.dmmf.datamodel
.
client
A jest-mock-extended
instance. If not provided, a new instance is created.
caseInsensitive
If true, all string comparisons are case insensitive.
Most common cases are covered, but not everything. Here is a rough list of the supported features:
TODO (set, push)
TODO (has, hasEvery, hasSome, isEmpty, equals)
Create a .env-cmdrc
file in the root of your project with the following content:
{
"postgres": {
"PROVIDER": "postgresql",
"DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/postgres?schema=public"
}
}
Create your tests in the __tests__
directory. You can use snapshot testing with either expect(res).toMatchSnapshot()
or expect(res).toMatchInlineSnapshot()
. This captures the result of your tests in a snapshot, which you can use to compare agains prisma-mock results.
Note: If you choose to use snapshot testing, make shore to first run your tests against the real database to create a snapshot of the expected result.
To run tests against a postgres database, run the following command:
yarn run test:postgres
To run tests against prisma-mock (in-memory database), run:
yarn test
FAQs
Mock prisma for unit testing database
We found that prisma-mock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.