Skip to content

Commit

Permalink
fix import and test logic
Browse files Browse the repository at this point in the history
  • Loading branch information
CachedaCodes committed Jan 19, 2024
1 parent 243fb87 commit dadaf8f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/x-components/src/components/display-emitter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe(`testing ${useOnDisplay.name} composable`, () => {

function renderUseOnDisplayTester({
element = document.createElement('div'),
triggerOnce = true
triggerOnce
}: RenderUseOnDisplayTesterOptions = {}): RenderUseOnDisplayTesterAPI {
const callbackSpy = jest.fn();

Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit dadaf8f

Please sign in to comment.