From 4047e2632e2620538c69fce54e26e3c2f91c9b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 23 Dec 2019 23:24:47 +0800 Subject: [PATCH] fix: responsiveObserve init miss sizing (#20400) * fix: init miss sizing * update mock test --- components/_util/responsiveObserve.ts | 2 ++ components/descriptions/__tests__/index.test.js | 9 --------- components/grid/__tests__/index.test.js | 9 --------- tests/setup.js | 6 +++--- 4 files changed, 5 insertions(+), 21 deletions(-) diff --git a/components/_util/responsiveObserve.ts b/components/_util/responsiveObserve.ts index 06e2ee2483..e017c802a7 100644 --- a/components/_util/responsiveObserve.ts +++ b/components/_util/responsiveObserve.ts @@ -77,6 +77,8 @@ const responsiveObserve = { mql, listener, }; + + listener(mql); }); }, }; diff --git a/components/descriptions/__tests__/index.test.js b/components/descriptions/__tests__/index.test.js index 6e745708e9..96cfb3e630 100644 --- a/components/descriptions/__tests__/index.test.js +++ b/components/descriptions/__tests__/index.test.js @@ -10,15 +10,6 @@ describe('Descriptions', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - jest.spyOn(window, 'matchMedia').mockImplementationOnce(query => ({ - addListener: (listener) => { - if (query === '(max-width: 575px)') { - listener({ matches: true }); - } - }, - removeListener: jest.fn(), - })); - afterEach(() => { MockDate.reset(); errorSpy.mockReset(); diff --git a/components/grid/__tests__/index.test.js b/components/grid/__tests__/index.test.js index fe64b37d29..fedb70ccf3 100644 --- a/components/grid/__tests__/index.test.js +++ b/components/grid/__tests__/index.test.js @@ -3,15 +3,6 @@ import { render, mount } from 'enzyme'; import { Col, Row } from '..'; import mountTest from '../../../tests/shared/mountTest'; -jest.spyOn(window, 'matchMedia').mockImplementationOnce(query => ({ - addListener: (listener) => { - if (query === '(max-width: 575px)') { - listener({ matches: true }); - } - }, - removeListener: jest.fn(), -})); - describe('Grid', () => { mountTest(Row); mountTest(Col); diff --git a/tests/setup.js b/tests/setup.js index 8fddc467a3..fc447196d0 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -12,10 +12,10 @@ if (typeof window !== 'undefined') { }; global.window.scrollTo = () => {}; // ref: https://github.com/ant-design/ant-design/issues/18774 - if (!global.window.matchMedia) { + if (!window.matchMedia) { Object.defineProperty(global.window, 'matchMedia', { - value: jest.fn(() => ({ - matches: true, + value: jest.fn(query => ({ + matches: query.includes('max-width'), addListener: () => {}, removeListener: () => {}, })),