From 72f7232929b882ad822d9d31d09540f1bc70abc8 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 23 Aug 2017 16:29:56 +0800 Subject: [PATCH] Add test cases for Card and Breadcrumb --- .../breadcrumb/__tests__/Breadcrumb.test.js | 2 +- components/card/__tests__/index.test.js | 27 +++++++++++++++++++ tests/setup.js | 16 +++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 components/card/__tests__/index.test.js diff --git a/components/breadcrumb/__tests__/Breadcrumb.test.js b/components/breadcrumb/__tests__/Breadcrumb.test.js index b84fbd7c7a..8d5dccaebb 100644 --- a/components/breadcrumb/__tests__/Breadcrumb.test.js +++ b/components/breadcrumb/__tests__/Breadcrumb.test.js @@ -14,7 +14,7 @@ describe('Breadcrumb', () => { }); // https://github.com/airbnb/enzyme/issues/875 - xit('warns on non-Breadcrumb.Item children', () => { + it('warns on non-Breadcrumb.Item children', () => { const MyCom = () =>
foo
; mount( diff --git a/components/card/__tests__/index.test.js b/components/card/__tests__/index.test.js new file mode 100644 index 0000000000..1c7155cd85 --- /dev/null +++ b/components/card/__tests__/index.test.js @@ -0,0 +1,27 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import Card from '../index'; + +const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout)); + +describe('Card', () => { + function fakeResizeWindowTo(wrapper, width) { + Object.defineProperties(wrapper.node.container, { + offsetWidth: { + get() { return width; }, + configurable: true, + }, + }); + window.resizeTo(width); + } + + it('resize card will trigger different padding', async () => { + const wrapper = mount(xxx); + fakeResizeWindowTo(wrapper, 1000); + await delay(0); + expect(wrapper.hasClass('ant-card-wider-padding')).toBe(true); + fakeResizeWindowTo(wrapper, 800); + await delay(0); + expect(wrapper.hasClass('ant-card-wider-padding')).toBe(false); + }); +}); diff --git a/tests/setup.js b/tests/setup.js index 79de834434..5a895ae2d2 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -1,3 +1,5 @@ +import { jsdom } from 'jsdom'; + // fixed jsdom miss if (typeof window !== 'undefined') { const matchMediaPolyfill = function matchMediaPolyfill() { @@ -11,3 +13,17 @@ if (typeof window !== 'undefined') { }; window.matchMedia = window.matchMedia || matchMediaPolyfill; } + +global.requestAnimationFrame = global.requestAnimationFrame || function (cb) { + return setTimeout(cb, 0); +}; + +const documentHTML = '
'; +global.document = jsdom(documentHTML); +global.window = document.parentWindow; + +global.window.resizeTo = (width, height) => { + global.window.innerWidth = width || global.window.innerWidth; + global.window.innerHeight = height || global.window.innerHeight; + global.window.dispatchEvent(new Event('resize')); +};