From d3e6fd8090528dc2a101ade74204792c88853417 Mon Sep 17 00:00:00 2001 From: zombiej Date: Fri, 1 May 2020 00:29:45 +0800 Subject: [PATCH] test: Fix test case --- .../date-picker/__tests__/focus.test.js | 24 ++++++++++++------- components/form/__tests__/label.test.js | 5 +++- components/input/__tests__/Password.test.js | 4 +++- components/input/__tests__/index.test.js | 6 +++-- .../__tests__/__snapshots__/demo.test.js.snap | 4 ---- tests/shared/focusTest.js | 5 +++- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/components/date-picker/__tests__/focus.test.js b/components/date-picker/__tests__/focus.test.js index e02358ffec..c1104c04da 100644 --- a/components/date-picker/__tests__/focus.test.js +++ b/components/date-picker/__tests__/focus.test.js @@ -18,22 +18,24 @@ describe('DatePicker', () => { }); it('should focus trigger input after select date in DatePicker', () => { - const wrapper = mount(); + const wrapper = mount(, { attachTo: document.body }); openPanel(wrapper); selectDate(wrapper, moment('2016-11-23')); expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).toBe(document.activeElement); + wrapper.unmount(); }); it('should focus trigger input after select date in RangePicker', () => { - const wrapper = mount(); + const wrapper = mount(, { attachTo: document.body }); openPanel(wrapper); selectDate(wrapper, moment('2016-11-23'), 0); selectDate(wrapper, moment('2016-11-28'), 1); expect(wrapper.find('.ant-calendar-picker').getDOMNode()).toBe(document.activeElement); + wrapper.unmount(); }); it('should focus trigger input after select date in MonthPicker', () => { - const wrapper = mount(); + const wrapper = mount(, { attachTo: document.body }); openPanel(wrapper); wrapper .find('.ant-calendar-month-panel-month') @@ -44,46 +46,52 @@ describe('DatePicker', () => { .at(6) .hasClass('ant-calendar-month-panel-selected-cell'); expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).toBe(document.activeElement); + wrapper.unmount(); }); it('should focus trigger input after select date in WeekPicker', () => { - const wrapper = mount(); + const wrapper = mount(, { attachTo: document.body }); openPanel(wrapper); selectDate(wrapper, moment('2016-11-23')); expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).toBe(document.activeElement); + wrapper.unmount(); }); it('should not auto focus trigger input when open prop is true in DatePicker', () => { - const wrapper = mount(); + const wrapper = mount(, { attachTo: document.body }); const wrapperInput = mount(); wrapperInput.instance().select(); expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).not.toBe( document.activeElement, ); + wrapper.unmount(); }); it('should not auto focus trigger input when open prop is true in RangePicker', () => { - const wrapper = mount(); + const wrapper = mount(, { attachTo: document.body }); const wrapperInput = mount(); wrapperInput.instance().select(); expect(wrapper.find('.ant-calendar-picker').getDOMNode()).not.toBe(document.activeElement); + wrapper.unmount(); }); it('should not auto focus trigger input when open prop is true in WeekPicker', () => { - const wrapper = mount(); + const wrapper = mount(, { attachTo: document.body }); const wrapperInput = mount(); wrapperInput.instance().select(); expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).not.toBe( document.activeElement, ); + wrapper.unmount(); }); it('should not auto focus trigger input when open prop is true in MonthPicker', () => { - const wrapper = mount(); + const wrapper = mount(, { attachTo: document.body }); const wrapperInput = mount(); wrapperInput.instance().select(); expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).not.toBe( document.activeElement, ); + wrapper.unmount(); }); }); diff --git a/components/form/__tests__/label.test.js b/components/form/__tests__/label.test.js index 06365d3258..6090bae84e 100644 --- a/components/form/__tests__/label.test.js +++ b/components/form/__tests__/label.test.js @@ -176,6 +176,7 @@ describe('Form', () => { , + { attachTo: document.body }, ); wrapper .find('Form label') @@ -197,6 +198,7 @@ describe('Form', () => { .at(1) .getDOMNode(), ).toBe(document.activeElement); + wrapper.unmount(); }); // https://github.com/ant-design/ant-design/issues/7693 @@ -208,7 +210,7 @@ describe('Form', () => { )); - const wrapper = mount(); + const wrapper = mount(, { attachTo: document.body }); expect(() => { wrapper .find('Form label') @@ -221,6 +223,7 @@ describe('Form', () => { .at(0) .getDOMNode(), ).toBe(document.activeElement); + wrapper.unmount(); }); it('should `labelAlign` work in FormItem', () => { diff --git a/components/input/__tests__/Password.test.js b/components/input/__tests__/Password.test.js index b699064bc2..edd89890a5 100644 --- a/components/input/__tests__/Password.test.js +++ b/components/input/__tests__/Password.test.js @@ -49,7 +49,9 @@ describe('Input.Password', () => { }); it('should keep focus state', () => { - const wrapper = mount(); + const wrapper = mount(, { + attachTo: document.body, + }); expect(document.activeElement).toBe( wrapper .find('input') diff --git a/components/input/__tests__/index.test.js b/components/input/__tests__/index.test.js index 1300fdf8a0..5def9427f7 100644 --- a/components/input/__tests__/index.test.js +++ b/components/input/__tests__/index.test.js @@ -299,7 +299,7 @@ describe('Input allowClear', () => { }); it('should focus input after clear', () => { - const wrapper = mount(); + const wrapper = mount(, { attachTo: document.body }); wrapper .find('.ant-input-clear-icon') .at(0) @@ -310,6 +310,7 @@ describe('Input allowClear', () => { .at(0) .getDOMNode(), ); + wrapper.unmount(); }); ['disabled', 'readOnly'].forEach(prop => { @@ -399,7 +400,7 @@ describe('TextArea allowClear', () => { }); it('should focus textarea after clear', () => { - const wrapper = mount(