【发布时间】:2021-07-04 02:35:47
【问题描述】:
我正在开玩笑中测试这个功能, 但我无法覆盖、调整屏幕大小或创建虚拟 dom。
我正在节点上运行此测试。 ps:我尝试使用jsdom但失败了。
functions.js
export const getScreenWidth = () => {
const screenWidth = window.screen.width;
if (screenWidth <= 425) return "mobile";
if (screenWidth <= 768) return "tablet";
if (screenWidth <= 1024) return "laptopSm";
if (screenWidth <= 1440) return "laptopLg";
if (screenWidth <= 2560) return "HD";
return screenWidth;
};
【问题讨论】:
标签: javascript jestjs window width screen