xxxxxxxxxx
beforeEach(() => {
jest.resetModules();
});
You can mock multiple exported function from file via below method see stackoverflow for reference
xxxxxxxxxx
// myModule.test.js
import { otherFn } from './myModule.js'
jest.mock('./myModule.js', () => ({
jest.requireActual('./myModule.js')), (
otherFn: jest.fn()
}))
describe('test category', () => {
it('tests something about otherFn', () => {
otherFn.mockReturnValue('foo')
expect(otherFn()).toBe('foo')
})
})
xxxxxxxxxx
jest.mock('./moduleName', () => ({
<function>: () => jest.fn(),
}));
// Create a mock for the TFile class
jest.mock('obsidian', () => {
return {
TFile: jest.fn().mockImplementation(() => {
return {
// Add any methods or properties you want to mock
basename: 'mock-basename.md',
path: 'mock-path',
extension: 'md',
stat: jest.fn(),
};
}),
};
});
xxxxxxxxxx
import randomColor from "randomcolor";
jest.mock("randomColor", () => {
return {
randomColor: () => {
return mockColor('#123456');
}
}
});
let mockColor = jest.fn();