Skip to content

Instantly share code, notes, and snippets.

@carlosble
Last active June 7, 2017 22:06
Show Gist options
  • Select an option

  • Save carlosble/4b724448261795a9b6bd63c725e53bb0 to your computer and use it in GitHub Desktop.

Select an option

Save carlosble/4b724448261795a9b6bd63c725e53bb0 to your computer and use it in GitHub Desktop.
Simulating changes in location
let stubApi = {};
let store;
let stubRouter = {
location: {
search: '',
query: {
toDay: '',
fromDay: ''
}
},
push: () => {};
};
function mountPageSimulatingNextQueryString(queryString) {
let simulatedLocation = {
location: {search: queryString}
};
const connectRouterToPageExplicitly = (state) => {
return {
routing: state.routing
};
};
const Page = factory.createPage(stubApi, const connectRouterToPageExplicitly);
page = mount(
<Provider store={store}>
<Page router={stubRouter} {...simulatedLocation}/>
</Provider>);
}
function dispatchLocationChange(store){
// Triggers the action that ends up with a call to
// componentWillReceiveProps with the new location
// Warning: This will break if future versions of react-router
// change the string literal for type of the action.
store.dispatch({
type: '@@router/LOCATION_CHANGE',
payload: {}
});
}
it('requests the report to the server when url changes', (done) => {
store = configureStore();
let sentFilters = null;
stubApi.getTotalsReport = (filters) => {
sentFilters = filters;
return Promise.resolve({});
};
mountPageSimulatingNextQueryString(currentQueryString());
dispatchLocationChange(store);
onceArequestToServerHasBeenProcessed(() => {
expect(sentFilters).toEqual(currentQueryString());
}, done);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment