diff --git a/packages/x-components/src/components/display-emitter.vue b/packages/x-components/src/components/display-emitter.vue index 03481d7117..1f4348c4c0 100644 --- a/packages/x-components/src/components/display-emitter.vue +++ b/packages/x-components/src/components/display-emitter.vue @@ -8,7 +8,7 @@ import { defineComponent, onUnmounted, PropType, Ref, ref } from 'vue'; import { MaybeElement } from '@vueuse/core'; import { TaggingRequest } from '@empathyco/x-types'; - import { useEmitDisplayEvent } from '../composables'; + import { useEmitDisplayEvent } from '../composables/use-on-display'; import { WireMetadata } from '../wiring'; import { NoElement } from './no-element'; diff --git a/packages/x-components/src/composables/__tests__/use-on-display.spec.ts b/packages/x-components/src/composables/__tests__/use-on-display.spec.ts index 24bed68908..1ff117460a 100644 --- a/packages/x-components/src/composables/__tests__/use-on-display.spec.ts +++ b/packages/x-components/src/composables/__tests__/use-on-display.spec.ts @@ -28,7 +28,7 @@ describe(`testing ${useOnDisplay.name} composable`, () => { function renderUseOnDisplayTester({ element = document.createElement('div'), - triggerOnce = true + triggerOnce }: RenderUseOnDisplayTesterOptions = {}): RenderUseOnDisplayTesterAPI { const callbackSpy = jest.fn(); @@ -70,14 +70,22 @@ describe(`testing ${useOnDisplay.name} composable`, () => { expect(callbackSpy).toHaveBeenCalled(); }); - it('triggers the callback only once by default', async () => { - const { callbackSpy, toggleElementVisibility } = renderUseOnDisplayTester(); + it('triggers the callback only once by default and when passing true', async () => { + let useOnDisplayReturn = renderUseOnDisplayTester(); - await toggleElementVisibility(); - await toggleElementVisibility(); - await toggleElementVisibility(); + await useOnDisplayReturn.toggleElementVisibility(); + await useOnDisplayReturn.toggleElementVisibility(); + await useOnDisplayReturn.toggleElementVisibility(); + + expect(useOnDisplayReturn.callbackSpy).toHaveBeenCalledTimes(1); + + useOnDisplayReturn = renderUseOnDisplayTester({ triggerOnce: true }); + + await useOnDisplayReturn.toggleElementVisibility(); + await useOnDisplayReturn.toggleElementVisibility(); + await useOnDisplayReturn.toggleElementVisibility(); - expect(callbackSpy).toHaveBeenCalledTimes(1); + expect(useOnDisplayReturn.callbackSpy).toHaveBeenCalledTimes(1); }); it('can remove the triggering repetition limitation', async () => {