Test And Mock Import With ES6

Fri Nov 15 2019

db.js

some coool stuf with code snippet here

export default name => {
    return true
}
handleSubmit(event) {
  alert('Your favorite flavor is: ' + this.state.value);
  event.preventDefault();
}

updateName.js

import dbSave from './db';
function updateName(name) {
    const data = dbSave(name)
    return data
}
export default updateName;

updateName.test.js

import updateName from './es6-updateName';
jest.mock('./db', () => {
    return {
        __esModule: true,
        default: jest.fn(() => true),
    };
});
describe('update name', () => {
    test('save success got true', () => {
        const res = updateName('dontcare')
        expect(res).toBe(true);
    });
});