【发布时间】:2019-06-14 10:33:22
【问题描述】:
我想编写一个单元测试,它期望一个变量包含一个特定值,具体取决于窗口的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 属性?
【问题讨论】:
标签: angular unit-testing testing jasmine angular8