From d2a435b14e6d17cb6c31065c1fef890408f86c79 Mon Sep 17 00:00:00 2001 From: Adam Berecz Date: Wed, 18 Oct 2023 11:22:14 +0200 Subject: [PATCH] test: popper mocks, test runner fix --- src/composables/useDropdown.js | 7 ++++--- .../@popperjs/core/lib/modifiers/flip.js | 1 + .../core/lib/modifiers/preventOverflow.js | 1 + .../@popperjs/core/lib/popper-lite.js | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/unit/__mocks__/@popperjs/core/lib/modifiers/flip.js create mode 100644 tests/unit/__mocks__/@popperjs/core/lib/modifiers/preventOverflow.js create mode 100644 tests/unit/__mocks__/@popperjs/core/lib/popper-lite.js diff --git a/src/composables/useDropdown.js b/src/composables/useDropdown.js index 793c1bc..3e77020 100644 --- a/src/composables/useDropdown.js +++ b/src/composables/useDropdown.js @@ -1,7 +1,7 @@ import { ref, toRefs, getCurrentInstance, computed, onMounted, onBeforeUnmount, nextTick } from 'vue' -import { createPopper } from '@popperjs/core/lib/popper-lite.js' -import preventOverflow from '@popperjs/core/lib/modifiers/preventOverflow.js' -import flip from '@popperjs/core/lib/modifiers/flip.js' +import { createPopper } from '@popperjs/core/lib/popper-lite' +import preventOverflow from '@popperjs/core/lib/modifiers/preventOverflow' +import flip from '@popperjs/core/lib/modifiers/flip' export default function useDropdown (props, context, dep) { @@ -104,6 +104,7 @@ export default function useDropdown (props, context, dep) return } + /* istanbul ignore next: popper mock */ popper.value = createPopper(multiselect.value, dropdown.value, { strategy: hasFixedParent(multiselect.value) ? /* istanbul ignore next: UI feature */ 'fixed' : undefined, placement: openDirection.value, diff --git a/tests/unit/__mocks__/@popperjs/core/lib/modifiers/flip.js b/tests/unit/__mocks__/@popperjs/core/lib/modifiers/flip.js new file mode 100644 index 0000000..56004c9 --- /dev/null +++ b/tests/unit/__mocks__/@popperjs/core/lib/modifiers/flip.js @@ -0,0 +1 @@ +export default {} \ No newline at end of file diff --git a/tests/unit/__mocks__/@popperjs/core/lib/modifiers/preventOverflow.js b/tests/unit/__mocks__/@popperjs/core/lib/modifiers/preventOverflow.js new file mode 100644 index 0000000..56004c9 --- /dev/null +++ b/tests/unit/__mocks__/@popperjs/core/lib/modifiers/preventOverflow.js @@ -0,0 +1 @@ +export default {} \ No newline at end of file diff --git a/tests/unit/__mocks__/@popperjs/core/lib/popper-lite.js b/tests/unit/__mocks__/@popperjs/core/lib/popper-lite.js new file mode 100644 index 0000000..0b61db4 --- /dev/null +++ b/tests/unit/__mocks__/@popperjs/core/lib/popper-lite.js @@ -0,0 +1,21 @@ +const createPopper = function (ref, el, options) { + const popper = { + setOptions: (cb) => { + let newOps = cb(options) + + popper.state.placement = newOps.placement + }, + update: () => {}, + destroy: () => {}, + state: { + placement: options.placement + }, + options, + } + + return popper +} + +export { + createPopper, +} \ No newline at end of file