我正在尝试编写一个处理登录的传奇故事的测试。下面是我的代码和遇到的问题:
const fakeStore = await runSaga(
{
getState: () => ({...state}),
dispatch: (action) => dispatchedActions.push(action)
},
apis.user.login, // this where the issue is from
payload
).done;
Tslint
错误消息:
Argument of type '(user: Authentication) => Promise<IUserResponse>' is not assignable to parameter of type 'Saga1<Authentication>'.
Property 'next' is missing in type 'Promise<IUserResponse>' but required in type 'Iterator<any>'.
这是
apis.user
apis{
user: {
login: (user: Authentication):Promise<IUserResponse> =>
axios.post('/api/login', user)
.then((res) => res.data)
.catch((res) => res.data || { message:"" }),
}
}
我不知道该怎么做
Saga1
类型我查看了类型定义,下面是它的样子:
export function runSaga<A, S, T1>(
storeInterface: RunSagaOptions<A, S>,
saga: Saga1<T1>,
arg1: T1): Task;
Saga1<T1>
type Saga1<T1> = (arg1: T1) => Iterator<any>;