From 742999ff286ba5c22f713b41728ea8260f7fa964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=81=8F=E5=8F=B3?= Date: Sun, 27 Aug 2017 16:53:36 +0800 Subject: [PATCH] Fix matchMedia not present in jest test (#7344) close #6560 close #3308 close #7341 --- components/carousel/index.tsx | 13 ++++++++----- tests/setup.js | 11 ----------- typings/custom-typings.d.ts | 4 +++- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/components/carousel/index.tsx b/components/carousel/index.tsx index 7af5d59928..7b4a8921b6 100644 --- a/components/carousel/index.tsx +++ b/components/carousel/index.tsx @@ -1,7 +1,8 @@ -// matchMedia polyfill for -// https://github.com/WickyNilliams/enquire.js/issues/82 +import React from 'react'; import debounce from 'lodash.debounce'; +// matchMedia polyfill for +// https://github.com/WickyNilliams/enquire.js/issues/82 if (typeof window !== 'undefined') { const matchMediaPolyfill = (mediaQuery: string): MediaQueryList => { return { @@ -15,9 +16,11 @@ if (typeof window !== 'undefined') { }; window.matchMedia = window.matchMedia || matchMediaPolyfill; } - -import SlickCarousel from 'react-slick'; -import React from 'react'; +// Use require over import (will be lifted up) +// make sure matchMedia polyfill run before require('react-slick') +// 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'; // Carousel diff --git a/tests/setup.js b/tests/setup.js index 2dfefb0cd4..06b8dad015 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -2,17 +2,6 @@ import { jsdom } from 'jsdom'; // fixed jsdom miss if (typeof window !== 'undefined') { - const matchMediaPolyfill = function matchMediaPolyfill() { - return { - matches: false, - addListener() { - }, - removeListener() { - }, - }; - }; - window.matchMedia = window.matchMedia || matchMediaPolyfill; - const documentHTML = '
'; global.document = jsdom(documentHTML); global.window = document.parentWindow; diff --git a/typings/custom-typings.d.ts b/typings/custom-typings.d.ts index f22b962967..eb370e708e 100644 --- a/typings/custom-typings.d.ts +++ b/typings/custom-typings.d.ts @@ -90,4 +90,6 @@ declare module "*.json" { export default value; } -declare module "prop-types" \ No newline at end of file +declare module "prop-types" + +declare function require(name: string): any;