Last active
August 14, 2018 06:46
-
-
Save jeznag/033c518d5f64e3424d64c99b45258431 to your computer and use it in GitHub Desktop.
final-test-for-mutation
This file contains 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
it('should trigger mutation when submit button clicked', async () => { | |
// NB submit button relies on the redux store having valid data | |
// which is why I set it here | |
set('reduxState', { | |
selectedMeters: [123], | |
selectedMeasurements: ['elec_power_real'], | |
exportParameters: { | |
dateRange: { | |
start: new Date(Date.UTC(2017, 0, 1)), | |
finish: new Date(Date.UTC(2018, 0, 1)) | |
} | |
}, | |
availableOptions: { | |
availableAggregationLevels: ['123'], | |
availableTimeAggregationLevels: ['sdfs'], | |
availableFileTypes: ['basd'], | |
availableTimeZones: ['45'] | |
} | |
}); | |
const button = getWrapper('button'); | |
button.simulate('click'); | |
// NB - without this, the mutation will still be processing when the expectation fires | |
// This is a technique from the official Apollo guide: | |
// https://www.apollographql.com/docs/guides/testing-react-components.html | |
await wait(0); | |
// pretty hacky but the best I could come up with | |
const result = JSON.parse( | |
getWrapper('[data-result]').props('data-result')['data-result'] | |
); | |
expect(result.data.availableOptions.submitted).toEqual(true); //tslint:disable-line | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment