From b536643f761ce3856fe54e8481fdefd26e41e3e7 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 27 Sep 2019 23:24:02 +0800 Subject: [PATCH] :white_check_mark: add test case for Collapse --- components/collapse/__tests__/index.test.js | 34 ++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/components/collapse/__tests__/index.test.js b/components/collapse/__tests__/index.test.js index 41ab35b98f66..35a065e9f8f8 100644 --- a/components/collapse/__tests__/index.test.js +++ b/components/collapse/__tests__/index.test.js @@ -1,9 +1,21 @@ import React from 'react'; import { mount } from 'enzyme'; -import Collapse from '..'; import mountTest from '../../../tests/shared/mountTest'; describe('Collapse', () => { + // Fix css-animation deps on these + // https://github.com/yiminghe/css-animation/blob/a5986d73fd7dfce75665337f39b91483d63a4c8c/src/Event.js#L44 + window.AnimationEvent = window.AnimationEvent || (() => {}); + window.TransitionEvent = window.TransitionEvent || (() => {}); + + afterAll(() => { + // restore it + delete window.AnimationEvent; + delete window.TransitionEvent; + }); + + // eslint-disable-next-line global-require + const Collapse = require('..').default; mountTest(Collapse); it('should support remove expandIcon', () => { @@ -24,4 +36,24 @@ describe('Collapse', () => { ); expect(wrapper.render()).toMatchSnapshot(); }); + + it('could be expand and collapse', () => { + jest.useFakeTimers(); + const wrapper = mount( + + + content + + , + ); + expect(wrapper.find('.ant-collapse-item').hasClass('ant-collapse-item-active')).toBe(false); + wrapper + .find('.ant-collapse-header') + .at(0) + .simulate('click'); + expect(wrapper.find('.ant-collapse-item').hasClass('ant-collapse-item-active')).toBe(true); + jest.runAllTimers(); + expect(wrapper.find('.ant-collapse-item').hasClass('ant-collapse-item-active')).toBe(true); + jest.useRealTimers(); + }); });