小编Saq*_*y G的帖子

如何用玩笑设置媒体查询?

我目前正在尝试对媒体查询进行测试,但我无法弄清楚。我怎么可能改变窗口的宽度,以便它反映到媒体查询。

我已经尝试了所有注释代码来模拟宽度但没有用。我知道它与 jsdom 有关,但无法弄清楚。

it('when image is WIDE and media match with medium', () => {
    Object.defineProperty(window, 'innerWidth', {writable: true, configurable: true, value: 900})

    // window.resizeBy = jest.fn();
    // window.resizeBy(900,300);
    //const mediaQuery = '(min-width: 790px)';
    // Object.defineProperty(window, "matchMedia", {
    //   value: jest.fn(() => { return { matches: true,media: mediaQuery } })
    // });
    // Object.defineProperty(window,'innerWidth', {
    //   configurable: true,
    //   writable: true,
    //   value: 790
    // });
    // Object.defineProperty(window,'innerHeight', {
    //   configurable: true,
    //   writable: true,
    //   value: 900
    // …
Run Code Online (Sandbox Code Playgroud)

unit-testing node.js reactjs jestjs

3
推荐指数
1
解决办法
5630
查看次数

标签 统计

jestjs ×1

node.js ×1

reactjs ×1

unit-testing ×1