I have this code on my test:
//app.test.js
jest.mock('notistack', () => ({
useSnackbar: jest.fn(),
}));
jest
.spyOn(notistack, 'useSnackbar')
.mockImplementation(() => ({ enqueueSnackbar }));
How can I move this function to a single file? all of my test contains this same function and I think its redundant to keep copy paste this code. I've tried moving this to other file and make function so I can import it
// helper.js
export function snackbar() {
jest.mock('notistack', () => ({
useSnackbar: jest.fn(),
}));
jest
.spyOn(notistack, 'useSnackbar')
.mockImplementation(() => ({ enqueueSnackbar }));
}
// app.test.js
import {snackbar} from 'helper.js';
snackbar();
// othercode for testing;
but everytime I run it, it always return me Cannot spyOn on a primitive value; undefined given.
how can I call it properly?