Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #15: added test to make sure combined reducers handle incoming …
…actions only once Change-Id: I9d4dc8d803372249df46b21b7feb57a89d783acf
- Loading branch information
Patrick Hund
committed
Jan 24, 2019
1 parent
321fdd9
commit f032aad
Showing
2 changed files
with
26 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
/* this is used only in unit tests */ | ||
export default type => [ | ||
(state = {}, action = {}) => (action.type === type ? { ...state, value: action.value } : state), | ||
{ type, value: type.toLowerCase() } | ||
]; | ||
/* global jest */ | ||
export default type => { | ||
const spy = jest.fn(); | ||
const reducer = (state = {}, action = {}) => { | ||
if (action.type === type) { | ||
spy(action.value); | ||
return { ...state, value: action.value }; | ||
} | ||
return state; | ||
}; | ||
const action = { type, value: type.toLowerCase() }; | ||
return [reducer, action, spy]; | ||
}; |