Skip to content

Commit

Permalink
fix: responsiveObserve init miss sizing (#20400)
Browse files Browse the repository at this point in the history
* fix: init miss sizing

* update mock test
  • Loading branch information
zombieJ authored Dec 23, 2019
1 parent 8501b70 commit 4047e26
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 21 deletions.
2 changes: 2 additions & 0 deletions components/_util/responsiveObserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const responsiveObserve = {
mql,
listener,
};

listener(mql);
});
},
};
Expand Down
9 changes: 0 additions & 9 deletions components/descriptions/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 0 additions & 9 deletions components/grid/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {},
})),
Expand Down

0 comments on commit 4047e26

Please sign in to comment.