Skip to content

Instantly share code, notes, and snippets.

@SherryH
Last active July 25, 2018 19:07
Show Gist options
  • Save SherryH/4a79188707db4799f269179b322ff059 to your computer and use it in GitHub Desktop.
Save SherryH/4a79188707db4799f269179b322ff059 to your computer and use it in GitHub Desktop.
A Jest Mock Example
import React from 'react';
import renderer from 'react-test-renderer';
//children mock need to be defined before parent module import
jest.mock('react-bootstrap-table', () => {
return {
BootstrapTable: 'BootstrapTable',
TableHeaderColumn: 'TableHeaderColumn',
};
});
jest.mock('../utils/SettingsUtil', () => {
let date = (new Date()).setHours(0,0,0,0);
const dummyQues ={
data: [{
question: 'What help can you get?',
answer: 'Get a couch to hold myself accountable',
updatedAt: date,
}, {
question: 'Whats the worst thing that could happen?',
answer: 'nothing',
updatedAt: new Date(date.valueOf() - 1000*60*60*24),
}],
};
return {
getReflectionsAjax: (userId, callback) => {
callback(dummyQues);
},
}
});
import Selfreflection from '../components/Selfreflection.js';
@dfkaye
Copy link

dfkaye commented Jul 25, 2018

@SherryH ~ Lines 5-10 from this gist saved my life today (25 July 2018). Thanks for posting 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment