typescript - TypeError: spy.mockReturnValue 不是一个函数,与 jest 和 Angular (nx) 一起使用
我有这个测试:
it('should display user email', () => {
const header = fixture.debugElement;
const spy = jest.spyOn(localStorage, 'getItem');
spy.mockReturnValue('[email ');
fixture.detectChanges();
expect(header.query(By.css(".user-label")).nativeElement.innerText).toContain("[email ");
})
运行时显示以下错误:TypeError: spy.mockReturnValue 不是函数
我正在使用 NX 版本 14.5.2,它已经自带 Jest (27.5.1) 和 Angular 14.0.2