Osamu
Osamu
PPrisma
Created by Osamu on 12/17/2024 in #help-and-questions
Mocking prisma client with javascript
Testing with ES6 requires to install jest-mock-extended and to create a file, the name can be anything:
import { mockDeep, mockReset } from "jest-mock-extended";

import { prisma } from './utils/prisma'

jest.mock('./utils/prisma', () => ({
prisma: mockDeep(),
// The line to activate es6, without it you'll get an error
__es6: true
}))

beforeEach(() => {
mockReset(prismaMock)
})

const prismaMock = prisma

export default prismaMock
import { mockDeep, mockReset } from "jest-mock-extended";

import { prisma } from './utils/prisma'

jest.mock('./utils/prisma', () => ({
prisma: mockDeep(),
// The line to activate es6, without it you'll get an error
__es6: true
}))

beforeEach(() => {
mockReset(prismaMock)
})

const prismaMock = prisma

export default prismaMock
Then, you can mock the api as you like
14 replies
PPrisma
Created by Osamu on 12/17/2024 in #help-and-questions
Mocking prisma client with javascript
Thank you
14 replies
PPrisma
Created by Osamu on 12/17/2024 in #help-and-questions
Mocking prisma client with javascript
/home/mohammad/Desktop/ALX/HealthVault/tests/patient.test.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import PatientController from "../controllers/PatientController"
^^^^^^

SyntaxError: Cannot use import statement outside a module

at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
/home/mohammad/Desktop/ALX/HealthVault/tests/patient.test.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import PatientController from "../controllers/PatientController"
^^^^^^

SyntaxError: Cannot use import statement outside a module

at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
I'm trying to use es6
14 replies
PPrisma
Created by Osamu on 12/17/2024 in #help-and-questions
Mocking prisma client with javascript
I've tried to implement it I kept getting problem related to ES6 I couldn't mock the prisma client sadly
14 replies
PPrisma
Created by Osamu on 12/17/2024 in #help-and-questions
Mocking prisma client with javascript
Pardon but it should work with es6 right? Or does it need more configuration?
14 replies
PPrisma
Created by Osamu on 12/17/2024 in #help-and-questions
Mocking prisma client with javascript
That's actually pretty cool thanks man I hope this gets into the documentation soon
14 replies