我正在尝试以开玩笑的方式编写一个单元测试,该单元测试全面涵盖了rxjs可观察的内容及其回调,但还不完全了解如何构建测试。
功能:
const item = MockItem;
// Need to spy on my service call that returns the observable
jest.spyOn(service, 'submitItem'); // Should I use mockImplementation()?
// Need to spy on the the methods being called in my callbacks
jest.spyOn(component, 'displayError');
jest.spyOn(component, 'getItems');
it('should submit item', () => {
component.submit(item);
expect(component.spinner).toBe(true);
expect(service.submitItem).toHaveBeenCalledWith(item);
});
测试:
{{1}}