mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
Fix matchMedia not present in jest test (#7344)
close #6560 close #3308 close #7341
This commit is contained in:
parent
d84452e8b8
commit
742999ff28
@ -1,7 +1,8 @@
|
|||||||
// matchMedia polyfill for
|
import React from 'react';
|
||||||
// https://github.com/WickyNilliams/enquire.js/issues/82
|
|
||||||
import debounce from 'lodash.debounce';
|
import debounce from 'lodash.debounce';
|
||||||
|
|
||||||
|
// matchMedia polyfill for
|
||||||
|
// https://github.com/WickyNilliams/enquire.js/issues/82
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
const matchMediaPolyfill = (mediaQuery: string): MediaQueryList => {
|
const matchMediaPolyfill = (mediaQuery: string): MediaQueryList => {
|
||||||
return {
|
return {
|
||||||
@ -15,9 +16,11 @@ if (typeof window !== 'undefined') {
|
|||||||
};
|
};
|
||||||
window.matchMedia = window.matchMedia || matchMediaPolyfill;
|
window.matchMedia = window.matchMedia || matchMediaPolyfill;
|
||||||
}
|
}
|
||||||
|
// Use require over import (will be lifted up)
|
||||||
import SlickCarousel from 'react-slick';
|
// make sure matchMedia polyfill run before require('react-slick')
|
||||||
import React from 'react';
|
// Fix https://github.com/ant-design/ant-design/issues/6560
|
||||||
|
// Fix https://github.com/ant-design/ant-design/issues/3308
|
||||||
|
const SlickCarousel = require('react-slick').default;
|
||||||
|
|
||||||
export type CarouselEffect = 'scrollx' | 'fade';
|
export type CarouselEffect = 'scrollx' | 'fade';
|
||||||
// Carousel
|
// Carousel
|
||||||
|
@ -2,17 +2,6 @@ import { jsdom } from 'jsdom';
|
|||||||
|
|
||||||
// fixed jsdom miss
|
// fixed jsdom miss
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
const matchMediaPolyfill = function matchMediaPolyfill() {
|
|
||||||
return {
|
|
||||||
matches: false,
|
|
||||||
addListener() {
|
|
||||||
},
|
|
||||||
removeListener() {
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
window.matchMedia = window.matchMedia || matchMediaPolyfill;
|
|
||||||
|
|
||||||
const documentHTML = '<!doctype html><html><body><div id="root"></div></body></html>';
|
const documentHTML = '<!doctype html><html><body><div id="root"></div></body></html>';
|
||||||
global.document = jsdom(documentHTML);
|
global.document = jsdom(documentHTML);
|
||||||
global.window = document.parentWindow;
|
global.window = document.parentWindow;
|
||||||
|
2
typings/custom-typings.d.ts
vendored
2
typings/custom-typings.d.ts
vendored
@ -91,3 +91,5 @@ declare module "*.json" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare module "prop-types"
|
declare module "prop-types"
|
||||||
|
|
||||||
|
declare function require(name: string): any;
|
||||||
|
Loading…
Reference in New Issue
Block a user