I\'m testing a React/Reflux application using Jest. I have the following function in a store:
onLoad: function() {
c
I have found jest mock instance function It's here
eg:
import expect from 'expect';
jest.mock('../libs/utils/Master');
import Master from '../libs/utils/Master';
Master.mockImplementation(() => {
return {
returnOne: jest.fn().mockReturnValueOnce(1)
}
})
describe('test Master', function() {
it('test search', function() {
let master = new Master();
expect(master.returnOne()).toEqual(1);
});
});
Almost there, all you need to do is
const onLoad = jest.fn().mockImplementation(function () {
var p1 = new Post();//Add your stuff here
this.posts = [p1];
console.log("mocked function");
});
PostStore.onLoad = onLoad.bind(PostStore); //PostStore is your object.