我正在使用Angular、NgRx和Jest。
我正在享受从商店阅读的服务
export class MyFacade {
configuration$ = this.store.select(selectors.selectConfiguration);
}
我在我的规格文件中使用它,在其中我测试的效果。我创建了一个模拟类,它是这样实现的
export class MyMockFacade {
configuration$ = of(configObject);
}
我的spec文件看起来像这样:
describe('Config Effects', () => {
const mockStore = new MockStore();
....
const mockFacade = new MyMockFacade();
let actions;
let effects: ConfigEffects;
beforeAll(() => {
Object.defineProperty(window, 'location', {
configurable: true,
value: { reload: jest.fn() }
});
});
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
ConfigEffects,
HttpClientModule,
provideMockActions(() => actions),
{ provide: Store, useValue: mockStore },
...
{ provide: MyFacade , useValue: mockFacade },
]
});
effects = TestBed.inject(ConfigEffects);
});
});
我希望能够在测试中更改从配置$返回的值。如何才能实现呢
it('should call ....', () => {
//I would like to be able to assigned new value here!
expect(effects.loadXXX$).toSatisfyOnFlush(() => {
...
});
});
1条答案
按热度按时间lf3rwulv1#
将
configuration$
设置为BehaviorSubject
,以便指定它应该发出的值: