我想编写一个单元测试,它期望一个变量包含一个取决于innerWidth
窗口的特定值。
在我的单元测试中,我使用window.innerWidth = 1000;
. 但是,我收到一条错误消息Cannot assign to 'innerWidth' because it is a read-only property.
。
代码(home.component.spec.ts):
xit('should order the cards in the appropriate order on desktop', () => {
spyOn(component, 'reOrderCards');
window.innerWidth = 1000;
})
有什么方法可以模拟该innerWidth
属性吗?