我的组件中有此条件。
{window.screen.width > 1000 && (
<WebFeatures
scrolling={this.handleScrollToStats}
ref_var={this.statsRef}
ref_app={this.myRef}
ref_reimburse={this.reimburse}
ref_expense={this.expense}
/>``
)}
我如何测试这种情况?
您可以在spyOn
上使用window.secreen.width
并返回测试所需的值:
jest.spyOn(window.screen, "width", "get").mockReturnValue(WIDTH);