Skip to content

Instantly share code, notes, and snippets.

@jeznag jeznag/test-for-mutation
Last active Aug 14, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.