Last active
July 25, 2018 19:07
-
-
Save SherryH/4a79188707db4799f269179b322ff059 to your computer and use it in GitHub Desktop.
A Jest Mock Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@SherryH ~ Lines 5-10 from this gist saved my life today (25 July 2018). Thanks for posting 🥇