可以观察到Rxjs的Jest单元测试

时间:2019-09-05 15:00:51

标签: unit-testing jestjs observable rxjs6

我正在尝试以开玩笑的方式编写一个单元测试,该单元测试全面涵盖了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}}

0 个答案:

没有答案