-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add TestAsyncThunk class for async thunk tests & decomposition loginB…
…yUsername.test
- Loading branch information
1 parent
3908868
commit a9ac6c3
Showing
2 changed files
with
38 additions
and
19 deletions.
There are no files selected for viewing
32 changes: 13 additions & 19 deletions
32
src/features/AuthByUsername/model/services/loginByUsername/loginByUsername.test.ts
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { IStateSchema } from 'shared/config/storeConfig/StateSchema'; | ||
import { AsyncThunkAction } from '@reduxjs/toolkit'; | ||
|
||
type ActionCreatorType<Return, Arg, RejectedValue> = (arg: Arg) => AsyncThunkAction<Return, Arg, { | ||
rejectValue: RejectedValue; | ||
}> | ||
|
||
export class TestAsyncThunk<Return, Arg, RejectedValue> { | ||
dispatch: jest.MockedFn<any>; | ||
getState: () => IStateSchema; | ||
actionCreator: ActionCreatorType<Return, Arg, RejectedValue>; | ||
|
||
constructor(actionCreator: ActionCreatorType<Return, Arg, RejectedValue>) { | ||
this.actionCreator = actionCreator; | ||
this.dispatch = jest.fn(); | ||
this.getState = jest.fn(); | ||
} | ||
|
||
async callThunk(arg: Arg) { | ||
const action = this.actionCreator( arg ); | ||
const result = await action( this.dispatch, this.getState, undefined ); | ||
|
||
return result; | ||
} | ||
} |