If you're testing with Jest, perhaps you already know to add manual mocks in your __mocks__
directory
├── src
│ └── index.js
├── __mocks__
│ └── @bugsnag
│ └── react-native.js
├── node_modules
├── jest.config.js
├── jest.setup.js
└── package.json
With __mocks__/@bugsnag/react-native.js
looking like:
module.exports = {
leaveBreadcrumb: jest.fn(),
notify: jest.fn(),
start: jest.fn(),
// other functions you call in your code
};
However, if you already have jest.setup.js
, you can mock Bugsnag like this:
// inside jest.setup.js
jest.mock("@bugsnag/react-native", () => ({
leaveBreadcrumb: jest.fn(),
notify: jest.fn(),
start: jest.fn(),
// other functions you call in your code
}));
// other mocked modules
The two approaches will work, so choose one or the other depending on you or your team's preference or need.
Sources:
Mocking Node modules
jest.mock
Top comments (0)