Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit744d06a

Browse files
committed
fix: wrong action type on reducer
1 parent09dc6fc commit744d06a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

‎src/action.model.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ export interface ActionClass<T extends SyncAction> {
2222

2323
exporttypeActionBody<S,AextendsSyncAction>=(
2424
state:S,
25-
action:Action,
25+
action:A,
2626
dispatch:<DextendsSyncAction>(action:D)=>Promise<D>,
2727
)=>S

‎tests/reducer.builder.spec.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ import { SyncAction, ReducerBuilder, StoreBuilder } from '../src'
66
interfaceSampleState{
77
isSyncActionCalled:boolean
88
isAsyncActionCalled?:boolean
9+
testValue?:string
910
}
1011

1112
interfaceSampleStore{
1213
reducer:SampleState
1314
}
1415

15-
classSampleSyncActionextendsSyncAction{}
16+
classSampleSyncActionextendsSyncAction{
17+
constructor(publicvalue:string){
18+
super()
19+
}
20+
}
1621

1722
classSampleAsyncActionextendsSyncAction{}
1823

@@ -43,7 +48,7 @@ describe('Reducer', () => {
4348
.withReducerBuilder('reducer',reducer)
4449
.build()
4550

46-
store.dispatch(newSampleSyncAction())
51+
store.dispatch(newSampleSyncAction('test1'))
4752

4853
it('should be called on dispatch sync action',()=>{
4954
expect(store.getState().reducer.isSyncActionCalled).equal(true)
@@ -52,6 +57,7 @@ describe('Reducer', () => {
5257

5358
describe('with async action handler',()=>{
5459
constdispatchedEvents:any[]=[]
60+
consttestValue='test'
5561
letstore:Store<SampleStore>
5662

5763
before(done=>{
@@ -61,12 +67,12 @@ describe('Reducer', () => {
6167
isAsyncActionCalled:false,
6268
})
6369
.handle(SampleAsyncAction,(state,action,dispatch)=>{
64-
dispatch(newSampleSyncAction())
70+
dispatch(newSampleSyncAction(testValue))
6571
return{ ...state,isAsyncActionCalled:true}
6672
})
6773
.handle(SampleSyncAction,(state,action)=>{
6874
setTimeout(done)
69-
return{ ...state,isSyncActionCalled:true}
75+
return{ ...state,isSyncActionCalled:true,testValue:action.value}
7076
})
7177

7278
store=newStoreBuilder<SampleStore>()
@@ -96,5 +102,9 @@ describe('Reducer', () => {
96102
it('should handle async action',()=>{
97103
expect(store.getState().reducer.isAsyncActionCalled).equal(true)
98104
})
105+
106+
it('should pass correct parameter value',()=>{
107+
expect(store.getState().reducer.testValue).equal(testValue)
108+
})
99109
})
100110
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp