我在代码中使用set
。它是这样使用的
import * as set from 'lodash/set';
................
@Effect({ dispatch: false })
redirectWithHref$: Observable<void> = this.actions$.pipe(
ofType<ActionWithPayload>(REDIRECT_TO_EXTERNAL),
map(action => action.payload),
tap(url => set(window.location, 'href', url))
);
................
我正在尝试spyOn
使用Jasmine,但它没有其他方法,当我试图窥探它抱怨它找不到要监视的对象时。
AuthEffects redirectWithHref should call set on the window with the payload as the url [74 ms]
Failed: <spyOn> : could not find an object to spy upon for default()
Usage: spyOn(<object>, <methodName>)
at t.<anonymous> src/app/store/auth/auth.effects.spec.ts:111:6
我的测试看起来像......
describe('redirectWithHref', () => {
fit('should call set on the window with the payload as the url', async(() => {
const { effects, actions } = setup({});
const setSpy = spyOn(set, 'default');
actions.next({ type: REDIRECT_TO_EXTERNAL, payload: 'http://foo.bar' });
expect(setSpy).toHaveBeenCalledWith('http://foo.bar');
}));
});
我怎么能窥探这个?使用Angular 6 w / NgRX 6