Skip to content

Commit

Permalink
Add test cases for Card and Breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Aug 23, 2017
1 parent 8bdad3d commit 72f7232
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/breadcrumb/__tests__/Breadcrumb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => <div>foo</div>;
mount(
<Breadcrumb>
Expand Down
27 changes: 27 additions & 0 deletions components/card/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -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(<Card title="xxx">xxx</Card>);
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);
});
});
16 changes: 16 additions & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jsdom } from 'jsdom';

// fixed jsdom miss
if (typeof window !== 'undefined') {
const matchMediaPolyfill = function matchMediaPolyfill() {
Expand All @@ -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 = '<!doctype html><html><body><div id="root"></div></body></html>';
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'));
};

0 comments on commit 72f7232

Please sign in to comment.