Open pankajnegi1893 opened 10 months ago
After putting below code in jest setup file. it's working fine.
export const mockDatabase = {
collections: {
get: jest.fn(),
},
};
jest.mock('@nozbe/watermelondb', () => ({
...jest.requireActual('@nozbe/watermelondb'),
Modal: jest.fn(),
Database: jest.fn(() => mockDatabase),
Q: {
sqlite: {
openDatabase: jest.fn(),
},
},
}));
After putting below code in jest setup file. it's working fine.
export const mockDatabase = { collections: { get: jest.fn(), }, }; jest.mock('@nozbe/watermelondb', () => ({ ...jest.requireActual('@nozbe/watermelondb'), Modal: jest.fn(), Database: jest.fn(() => mockDatabase), Q: { sqlite: { openDatabase: jest.fn(), }, }, }));
@pankajnegi1893 I have tried your solution but I'm getting this error:
TypeError: Cannot read properties of undefined (reading 'getRandomIds')
Do you have any idea how to fix this?
@MuhammadNaumanShafique I had the same error and updating to 0.27.1 fixed it for me
I am getting below error when running my test case
I have checked regarding this error but still getting same issue. below are the babel.config.js file I am having.
babel.config.js
tsconfig.json
{ "extends": "@tsconfig/react-native/tsconfig.json", "compilerOptions": { "experimentalDecorators": true, "emitDecoratorMetadata": true, "paths": { // this allows sub-package imports from src; fx. '@nozbe/watermelondb/decorators' "@nozbe/watermelondb/": ["./src/db/"] } }, "include": [ "./*.ts", "./src/*/.ts" // this is just used to validate everything, not just imported declarations ] }
package.json
"@nozbe/watermelondb": "^0.27.1", "@nozbe/with-observables": "^1.6.0",