Add test cases for Card and Breadcrumb

pull/7291/merge
afc163 8 years ago
parent 8bdad3d418
commit 72f7232929

@ -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>

@ -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);
});
});

@ -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 = '<!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'));
};

Loading…
Cancel
Save