From 116c8e4cefcbf30fcbe67493a6ec29f5b694a201 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sun, 20 Jun 2021 22:53:42 +0800 Subject: [PATCH] test: update snap --- components/anchor/Anchor.tsx | 4 +- components/avatar/__tests__/Avatar.test.js | 12 +- .../__snapshots__/Avatar.test.js.snap | 16 +- components/back-top/__tests__/index.test.js | 15 +- components/badge/Badge.tsx | 17 +- .../__snapshots__/index.test.js.snap | 20 +- .../__snapshots__/Breadcrumb.test.js.snap | 2 +- .../__snapshots__/index.test.js.snap | 6 +- .../__snapshots__/index.test.js.snap | 4 +- .../__snapshots__/index.test.js.snap | 30 +- .../__snapshots__/index.test.js.snap | 2 +- .../__snapshots__/index.test.js.snap | 19 +- .../__snapshots__/DatePicker.test.js.snap | 2 +- .../__snapshots__/RangePicker.test.js.snap | 4 +- .../__snapshots__/other.test.js.snap | 8 +- .../__snapshots__/Drawer.test.js.snap | 8 +- .../__snapshots__/DrawerEvent.test.js.snap | 2 +- .../dropdown-button.test.js.snap | 2 +- components/form/context.ts | 3 + .../__snapshots__/index.test.js.snap | 2 +- components/layout/Sider.tsx | 2 +- .../__snapshots__/index.test.js.snap | 1428 ++++++++--------- .../__snapshots__/Modal.test.js.snap | 6 +- 23 files changed, 812 insertions(+), 802 deletions(-) diff --git a/components/anchor/Anchor.tsx b/components/anchor/Anchor.tsx index 62e599f27..41772337b 100644 --- a/components/anchor/Anchor.tsx +++ b/components/anchor/Anchor.tsx @@ -88,7 +88,7 @@ export default defineComponent({ scrollEvent: null, animating: false, }); - const activeLink = ref(); + const activeLink = ref(null); const getContainer = computed(() => { const { getContainer } = props; return getContainer || getTargetContainer.value || getDefaultContainer; @@ -122,7 +122,7 @@ export default defineComponent({ }; const setCurrentActiveLink = (link: string) => { const { getCurrentAnchor } = props; - if (activeLink.value !== link) { + if (activeLink.value === link) { return; } activeLink.value = typeof getCurrentAnchor === 'function' ? getCurrentAnchor() : link; diff --git a/components/avatar/__tests__/Avatar.test.js b/components/avatar/__tests__/Avatar.test.js index 91d028d39..f9537dba0 100644 --- a/components/avatar/__tests__/Avatar.test.js +++ b/components/avatar/__tests__/Avatar.test.js @@ -186,7 +186,7 @@ describe('Avatar Render', () => { }); }); - it('fallback', async () => { + it('fallback', () => { const div = global.document.createElement('div'); global.document.body.appendChild(div); const wrapper = mount( @@ -201,11 +201,9 @@ describe('Avatar Render', () => { }, { attachTo: div }, ); - await asyncExpect(async () => { - await wrapper.find('img').trigger('error'); - expect(wrapper.html()).toMatchSnapshot(); - wrapper.unmount(); - global.document.body.removeChild(div); - }, 0); + wrapper.find('img').trigger('error'); + expect(wrapper.html()).toMatchSnapshot(); + wrapper.unmount(); + global.document.body.removeChild(div); }); }); diff --git a/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap b/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap index a17048216..df10ee4ee 100644 --- a/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap +++ b/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap @@ -1,18 +1,18 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Avatar Render adjusts component size to 24 when window size is xs 1`] = ``; +exports[`Avatar Render adjusts component size to 24 when window size is xs 1`] = ``; -exports[`Avatar Render adjusts component size to 32 when window size is sm 1`] = ``; +exports[`Avatar Render adjusts component size to 32 when window size is sm 1`] = ``; -exports[`Avatar Render adjusts component size to 40 when window size is md 1`] = ``; +exports[`Avatar Render adjusts component size to 40 when window size is md 1`] = ``; -exports[`Avatar Render adjusts component size to 64 when window size is lg 1`] = ``; +exports[`Avatar Render adjusts component size to 64 when window size is lg 1`] = ``; -exports[`Avatar Render adjusts component size to 80 when window size is xl 1`] = ``; +exports[`Avatar Render adjusts component size to 80 when window size is xl 1`] = ``; -exports[`Avatar Render adjusts component size to 100 when window size is xxl 1`] = ``; +exports[`Avatar Render adjusts component size to 100 when window size is xxl 1`] = ``; -exports[`Avatar Render fallback 1`] = `A`; +exports[`Avatar Render fallback 1`] = ``; exports[`Avatar Render should calculate scale of avatar children correctly 1`] = ` DOMWrapper { @@ -40,4 +40,4 @@ DOMWrapper { } `; -exports[`Avatar Render should calculate scale of avatar children correctly with gap 1`] = `Avatar`; +exports[`Avatar Render should calculate scale of avatar children correctly with gap 1`] = `Avatar`; diff --git a/components/back-top/__tests__/index.test.js b/components/back-top/__tests__/index.test.js index 791bf4cef..b7a4c3cbf 100644 --- a/components/back-top/__tests__/index.test.js +++ b/components/back-top/__tests__/index.test.js @@ -8,18 +8,19 @@ describe('BackTop', () => { props: { visibilityHeight: -1, }, + attachTo: 'body', }); const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => { window.scrollY = y; window.pageYOffset = y; + document.documentElement.scrollTop = y; }); window.scrollTo(0, 400); - // trigger scroll manually - wrapper.vm.handleScroll(); - await sleep(); + expect(document.documentElement.scrollTop).toBe(400); + await sleep(10); wrapper.find('.ant-back-top').trigger('click'); await sleep(500); - expect(window.pageYOffset).toBe(0); + expect(document.documentElement.scrollTop).toBe(0); scrollToSpy.mockRestore(); }); it('support onClick', async () => { @@ -29,15 +30,15 @@ describe('BackTop', () => { visibilityHeight: -1, onClick, }, + attachTo: 'body', }); const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => { window.scrollY = y; window.pageYOffset = y; }); + document.dispatchEvent(new Event('scroll')); window.scrollTo(0, 400); - // trigger scroll manually - wrapper.vm.handleScroll(); - await sleep(); + await sleep(10); wrapper.find('.ant-back-top').trigger('click'); expect(onClick).toHaveBeenCalled(); scrollToSpy.mockRestore(); diff --git a/components/badge/Badge.tsx b/components/badge/Badge.tsx index e3d5aa57b..6e16cf613 100644 --- a/components/badge/Badge.tsx +++ b/components/badge/Badge.tsx @@ -157,13 +157,16 @@ export default defineComponent({ visible || !text ? null : {text}; // >>> Display Component - const displayNode = cloneElement( - slots.count?.(), - { - style: mergedStyle, - }, - false, - ); + const displayNode = + typeof count === 'object' || (count === undefined && slots.count) + ? cloneElement( + count ?? slots.count?.(), + { + style: mergedStyle, + }, + false, + ) + : null; const badgeClassName = classNames( pre, diff --git a/components/badge/__tests__/__snapshots__/index.test.js.snap b/components/badge/__tests__/__snapshots__/index.test.js.snap index db5754c14..5d9c546ac 100644 --- a/components/badge/__tests__/__snapshots__/index.test.js.snap +++ b/components/badge/__tests__/__snapshots__/index.test.js.snap @@ -2,47 +2,47 @@ exports[`Badge badge should support float number 1`] = `"3.5"`; -exports[`Badge badge should support float number 2`] = `3.5`; +exports[`Badge badge should support float number 2`] = `3.5`; exports[`Badge render correct with negative number 1`] = ` -
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
- -0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
+-
1
0
+-
1
0
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
+4
`; exports[`Badge should render when count is changed 1`] = ` -0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
+1
0
1
2
3
4
5
6
7
8
9
0
`; exports[`Badge should render when count is changed 2`] = ` -0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
+1
1
2
3
4
5
6
7
8
9
0
1
`; exports[`Badge should render when count is changed 3`] = ` -0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
+1
1
2
3
4
5
6
7
8
9
0
1
`; exports[`Badge should render when count is changed 4`] = ` -0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
+1
0
1
2
3
4
5
6
7
8
9
0
`; exports[`Badge should render when count is changed 5`] = ` -0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
+9
`; exports[`Badge should support offset when count is a VueNode 1`] = ` -head +head `; diff --git a/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.js.snap b/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.js.snap index e0ffda91b..ca021ed63 100644 --- a/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.js.snap +++ b/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.js.snap @@ -8,7 +8,7 @@ exports[`Breadcrumb should not display Breadcrumb Item when its children is fals