Skip to content

Instantly share code, notes, and snippets.

@jeznag
Last active August 14, 2018 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeznag/033c518d5f64e3424d64c99b45258431 to your computer and use it in GitHub Desktop.
Save jeznag/033c518d5f64e3424d64c99b45258431 to your computer and use it in GitHub Desktop.
final-test-for-mutation
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