-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react): upgrade redux toolkit version and generated slice code (#…
- Loading branch information
Showing
8 changed files
with
209 additions
and
117 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
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
67 changes: 40 additions & 27 deletions
67
packages/react/src/schematics/redux/files/__directory__/__fileName__.slice.spec.ts__tmpl__
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,40 +1,53 @@ | ||
import { | ||
<%= propertyName %>Reducer, | ||
get<%= className %>Start, | ||
get<%= className %>Failure, | ||
get<%= className %>Success | ||
} from './<%= fileName %>.slice'; | ||
import { <%= propertyName %>Actions, <%= propertyName %>Adapter, <%= propertyName %>Reducer } from './<%= fileName %>.slice'; | ||
|
||
describe('<%= propertyName %> reducer', () => { | ||
it('should handle initial state', () => { | ||
expect(<%= propertyName %>Reducer(undefined, { type: '' })).toMatchObject({ | ||
entities: [] | ||
const expected = <%= propertyName %>Adapter.getInitialState({ | ||
loadingStatus: 'not loaded', | ||
error: null | ||
}); | ||
|
||
expect(<%= propertyName %>Reducer(undefined, { type: '' })).toEqual(expected); | ||
}); | ||
|
||
it('should handle get <%= propertyName %> actions', () => { | ||
let state = <%= propertyName %>Reducer(undefined, get<%= className %>Start()); | ||
it('should handle fetch<%= className %>s', () => { | ||
let state = <%= propertyName %>Reducer( | ||
undefined, | ||
<%= propertyName %>Actions.fetch<%= className %>s.pending(null, null) | ||
); | ||
|
||
expect(state).toEqual({ | ||
loaded: false, | ||
error: null, | ||
entities: [] | ||
}); | ||
expect(state).toEqual( | ||
expect.objectContaining({ | ||
loadingStatus: 'loading', | ||
error: null, | ||
entities: {} | ||
}) | ||
); | ||
|
||
state = <%= propertyName %>Reducer(state, get<%= className %>Success([{ id: 1 }])); | ||
state = <%= propertyName %>Reducer( | ||
state, | ||
<%= propertyName %>Actions.fetch<%= className %>s.fulfilled([{ id: 1 }], null, null) | ||
); | ||
|
||
expect(state).toEqual({ | ||
loaded: true, | ||
error: null, | ||
entities: [{ id: 1 }] | ||
}); | ||
expect(state).toEqual( | ||
expect.objectContaining({ | ||
loadingStatus: 'loaded', | ||
error: null, | ||
entities: { 1: { id: 1 } } | ||
}) | ||
); | ||
|
||
state = <%= propertyName %>Reducer(state, get<%= className %>Failure('Uh oh')); | ||
state = <%= propertyName %>Reducer( | ||
state, | ||
<%= propertyName %>Actions.fetch<%= className %>s.rejected(new Error('Uh oh'), null, null) | ||
); | ||
|
||
expect(state).toEqual({ | ||
loaded: true, | ||
error: 'Uh oh', | ||
entities: [{ id: 1 }] | ||
}); | ||
expect(state).toEqual( | ||
expect.objectContaining({ | ||
loadingStatus: 'error', | ||
error: 'Uh oh', | ||
entities: { 1: { id: 1 } } | ||
}) | ||
); | ||
}); | ||
}); |
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
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
Oops, something went wrong.