Created
October 1, 2017 14:47
-
-
Save KTruong008/91a932624e8463ab31bafaacbd75e63e to your computer and use it in GitHub Desktop.
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
// reducer.js | |
export const initialState = { | |
authenticated: false, | |
authenticating: false, | |
}; | |
export const loginReducer = ( | |
state = initialState, | |
action | |
) => { | |
switch (action.type) { | |
case AUTHENTICATION.AUTHENTICATED: | |
return { ...state, authenticating: false, authenticated: action.payload.authenticated }; | |
default: | |
return state; | |
} | |
}; | |
// action.js | |
export const switchAuthenticatedFlag = status => { | |
return { | |
type: 'LOGIN/AUTHENTICATED', | |
payload: { | |
authenticated: status, | |
}, | |
}; | |
}; | |
// reducer.test.js | |
describe('Login Reducers', () => { | |
it('properly captures a dispatch to change authenticated state', () => { | |
expect(loginReducer(initialState, switchAuthenticatedFlag(true))) | |
.toEqual({ | |
authenticated: true, | |
authenticating: false, | |
}); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment