From 44d7cc2426f6f05850a17320dfaa0baa6d3de043 Mon Sep 17 00:00:00 2001 From: jeremywu <591449570@qq.com> Date: Mon, 24 Aug 2020 00:00:20 +0800 Subject: [PATCH] fix(popper): fix popper's mechanism (#177) - Rewrite popper's render method \ --- packages/popper/__tests__/popper.spec.ts | 13 +- packages/popper/doc/basic.vue | 21 +- packages/popper/src/index.vue | 252 ++++++++++++++--------- packages/popper/src/popper.d.ts | 10 + packages/utils/util.ts | 8 + 5 files changed, 193 insertions(+), 111 deletions(-) create mode 100644 packages/popper/src/popper.d.ts diff --git a/packages/popper/__tests__/popper.spec.ts b/packages/popper/__tests__/popper.spec.ts index c357943a41..acb4de4feb 100644 --- a/packages/popper/__tests__/popper.spec.ts +++ b/packages/popper/__tests__/popper.spec.ts @@ -80,16 +80,11 @@ describe('Popper.vue', () => { }) test('append to body', () => { - const { appendChild } = document.body - document.body.appendChild = jest.fn(child => { - return appendChild.call(document.body, child) - }) - let wrapper = _mount() - expect(wrapper.find('[role="tooltip"]').exists()).toBe(false) - expect(document.body.appendChild).toHaveBeenCalled() - - document.body.appendChild = appendChild + const selector = '[role="tooltip"]' + expect(wrapper.find(selector).exists()).toBe(false) + // Due to the parent node of popper is Transition so we should match the grandparent + expect(document.querySelector(selector).parentElement.parentElement).toBe(document.body) wrapper = _mount({ appendToBody: false, }) diff --git a/packages/popper/doc/basic.vue b/packages/popper/doc/basic.vue index 91e79db5a7..e9ebf28a38 100644 --- a/packages/popper/doc/basic.vue +++ b/packages/popper/doc/basic.vue @@ -1,7 +1,10 @@