Skip to content

Commit

Permalink
fix(redux): fixed location object, now including search and hash, too
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLambrecht authored and ZauberNerd committed Mar 27, 2019
1 parent b8a6905 commit 4bf81d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/redux/action-creator-dispatcher/mixin.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ReduxActionCreatorServerMixin extends ReduxActionCreatorCommonMixin {

async fetchData(data) {
if (this.canPrefetchOnServer().every(value => value)) {
await this.dispatchAll(createLocation(this.request.path));
await this.dispatchAll(createLocation(this.request.originalUrl));
this.prefetchedOnServer = true;
}
return data;
Expand Down
17 changes: 15 additions & 2 deletions packages/spec/integration/redux/__tests__/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ describe('redux developmet server', () => {
await page.close();
});

it('executes route-matching action creators also if a search query or hash is present', async () => {
const { page, getInnerText } = await createPage();
await page.goto(url + '/increment?foo=bar#hash', {
waitUntil: 'networkidle2',
});

const count = await getInnerText('counter');

expect(count).toBe('1');

await page.close();
});

it('executes route-matching action creators with fetch', async () => {
const { page, getInnerText } = await createPage();
await page.goto(url + '/increment-fetch', { waitUntil: 'networkidle2' });
Expand All @@ -65,13 +78,13 @@ describe('redux developmet server', () => {

it('executes route-matching action creators with react-router-location as part of their second argument', async () => {
const { page, getInnerText } = await createPage();
await page.goto(url + '/location-test', {
await page.goto(url + '/location-test?foo=bar', {
waitUntil: 'networkidle2',
});

const param = await getInnerText('value');

expect(param).toBe('/location-test');
expect(param).toBe('?foo=bar');

await page.close();
});
Expand Down
4 changes: 2 additions & 2 deletions packages/spec/integration/redux/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const incrementFetch = () => dispatch => {

const setParam = ({ param }) => ({ type: 'SET_VALUE', payload: param });

const setLocationPathname = (params, { location: { pathname } }) => {
const setLocationPathname = (params, { location: { search } }) => {
return {
type: 'SET_VALUE',
payload: pathname,
payload: search,
};
};

Expand Down

0 comments on commit 4bf81d8

Please sign in to comment.