[英]Angular ngrx Property 'payload' does not exist on type 'Action'
I just update from Angular 8 to Angular 9 and I have some problems that I don't really understand.我刚刚从 Angular 8 更新到 Angular 9,但我遇到了一些我不太了解的问题。 I saw some few posts who looks similar to my problem but doesn't help me to solve anything (maybe because of me and not the solution given by others)
我看到了一些看起来与我的问题相似但没有帮助我解决任何问题的帖子(可能是因为我而不是其他人给出的解决方案)
So, the problem is when I launch ng test I have this error:所以,问题是当我启动ng test我有这个错误:
error TS2339: Property 'payload' does not exist on type 'Action'.
错误 TS2339:“动作”类型上不存在属性“有效载荷”。
The problem is on the spy.calls.allArgs()[1][0].payload.user
.问题出在
spy.calls.allArgs()[1][0].payload.user
。 It's like the link between setUser
and spy.calls.allArgs
doesn't exist any more.这就像
setUser
和spy.calls.allArgs
之间的链接不再存在。
login.service.spec.ts登录.service.spec.ts
it('should get token', () => {
const store = TestBed.inject(Store);
const spy = spyOn(store, 'dispatch').and.callThrough();
service.getToken('root', '', 'MY_DATABASE').subscribe(() => {
expect(spy).toHaveBeenCalled();
spy.calls.allArgs()[1][0]);
const user: User = spy.calls.allArgs()[1][0].payload.user;
expect(user.database).toBe('MY_DATABASE');
});
});
login.actions.ts登录.actions.ts
export class SetUser implements Action {
readonly type = LOGIN_ACTION_TYPES.SET_USER;
constructor(public payload: SetUserActionInterface) {}
}
interface SetUserActionInterface {
user: User;
}
What's the problem in my code?我的代码有什么问题?
I don't know if this is a good approach but try:我不知道这是否是一个好方法,但请尝试:
// we are casting it to be of type SetUser where payload should be there.
const user: User = (spy.calls.allArgs()[1][0] as SetUser).payload.user;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.