Download react-boilerplate/app/containers/App/tests/reducer.test.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-boilerplate/app/containers/App/tests/reducer.test.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-boilerplate/app/containers/App/tests/reducer.test.js
-
curl -L -o reducer.test.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-boilerplate/app/containers/App/tests/reducer.test.js
1.65 kB
| import produce from 'immer'; | |
| import appReducer from '../reducer'; | |
| import { loadRepos, reposLoaded, repoLoadingError } from '../actions'; | |
| /* eslint-disable default-case, no-param-reassign */ | |
| describe('appReducer', () => { | |
| let state; | |
| beforeEach(() => { | |
| state = { | |
| loading: false, | |
| error: false, | |
| currentUser: false, | |
| userData: { | |
| repositories: false, | |
| }, | |
| }; | |
| }); | |
| it('should return the initial state', () => { | |
| const expectedResult = state; | |
| expect(appReducer(undefined, {})).toEqual(expectedResult); | |
| }); | |
| it('should handle the loadRepos action correctly', () => { | |
| const expectedResult = produce(state, draft => { | |
| draft.loading = true; | |
| draft.error = false; | |
| draft.userData.repositories = false; | |
| }); | |
| expect(appReducer(state, loadRepos())).toEqual(expectedResult); | |
| }); | |
| it('should handle the reposLoaded action correctly', () => { | |
| const fixture = [ | |
| { | |
| name: 'My Repo', | |
| }, | |
| ]; | |
| const username = 'test'; | |
| const expectedResult = produce(state, draft => { | |
| draft.userData.repositories = fixture; | |
| draft.loading = false; | |
| draft.currentUser = username; | |
| }); | |
| expect(appReducer(state, reposLoaded(fixture, username))).toEqual( | |
| expectedResult, | |
| ); | |
| }); | |
| it('should handle the repoLoadingError action correctly', () => { | |
| const fixture = { | |
| msg: 'Not found', | |
| }; | |
| const expectedResult = produce(state, draft => { | |
| draft.error = fixture; | |
| draft.loading = false; | |
| }); | |
| expect(appReducer(state, repoLoadingError(fixture))).toEqual( | |
| expectedResult, | |
| ); | |
| }); | |
| }); | |