Skip to content

Commit

Permalink
fix display composable tets
Browse files Browse the repository at this point in the history
  • Loading branch information
CachedaCodes committed Mar 21, 2024
1 parent 0f99e2b commit a06a53e
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ref, nextTick } from 'vue';
import { useElementVisibility } from '@vueuse/core';
import { TaggingRequest } from '@empathyco/x-types';
import { useEmitDisplayEvent, useOnDisplay } from '../use-on-display';
import { use$x } from '../use-$x';
import { WireMetadata } from '../../wiring';
import { bus } from '../../plugins/index';

jest.mock('@vueuse/core', () => ({
useElementVisibility: jest.fn()
Expand All @@ -12,14 +12,8 @@ jest.mock('@vueuse/core', () => ({
const refElementVisibility = ref(false);
(useElementVisibility as jest.Mock).mockReturnValue(refElementVisibility);

jest.mock('../use-$x', () => ({
use$x: jest.fn()
}));

const $xEmitSpy = jest.fn();
(use$x as jest.Mock).mockReturnValue({
emit: $xEmitSpy
});
const emitSpy = jest.fn();
jest.spyOn(bus, 'emit' as any).mockImplementation(emitSpy);

describe(`testing ${useOnDisplay.name} composable`, () => {
beforeEach(() => {
Expand Down Expand Up @@ -178,8 +172,8 @@ describe(`testing ${useEmitDisplayEvent.name} composable`, () => {

await toggleElementVisibility();

expect($xEmitSpy).toHaveBeenCalled();
expect($xEmitSpy).toHaveBeenCalledWith(
expect(emitSpy).toHaveBeenCalled();
expect(emitSpy).toHaveBeenCalledWith(
'TrackableElementDisplayed',
{
tagging: {
Expand All @@ -203,11 +197,11 @@ describe(`testing ${useEmitDisplayEvent.name} composable`, () => {

await toggleElementVisibility();

expect($xEmitSpy).toHaveBeenCalled();
expect($xEmitSpy).toHaveBeenCalledWith(
expect(emitSpy).toHaveBeenCalled();
expect(emitSpy).toHaveBeenCalledWith(
'TrackableElementDisplayed',
expect.anything(),
eventMetadata
expect.objectContaining({ ...eventMetadata })
);
});

Expand All @@ -218,7 +212,7 @@ describe(`testing ${useEmitDisplayEvent.name} composable`, () => {
await toggleElementVisibility();
await toggleElementVisibility();

expect($xEmitSpy).toHaveBeenCalledTimes(1);
expect(emitSpy).toHaveBeenCalledTimes(1);
});

it('exposes the current visibility of the element', async () => {
Expand All @@ -239,7 +233,7 @@ describe(`testing ${useEmitDisplayEvent.name} composable`, () => {
unwatchDisplay();

await toggleElementVisibility();
expect($xEmitSpy).not.toHaveBeenCalled();
expect(emitSpy).not.toHaveBeenCalled();
});
});

Expand Down

0 comments on commit a06a53e

Please sign in to comment.