From ddc66ea4dce9953dfab2668d90d741e2736c649f Mon Sep 17 00:00:00 2001 From: acondal Date: Mon, 25 Mar 2024 15:37:03 +0100 Subject: [PATCH] tests(suggestion): fix emitting events tests EMP-3656 --- .../suggestions/__tests__/base-suggestion.spec.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/x-components/src/components/suggestions/__tests__/base-suggestion.spec.ts b/packages/x-components/src/components/suggestions/__tests__/base-suggestion.spec.ts index a841d37370..c02ff1cf9f 100644 --- a/packages/x-components/src/components/suggestions/__tests__/base-suggestion.spec.ts +++ b/packages/x-components/src/components/suggestions/__tests__/base-suggestion.spec.ts @@ -2,7 +2,6 @@ import { Suggestion } from '@empathyco/x-types'; import { mount, Wrapper } from '@vue/test-utils'; import Vue from 'vue'; import { createQuerySuggestion } from '../../../__stubs__/index'; -import { XPlugin } from '../../../plugins/x-plugin'; import { normalizeString } from '../../../utils/normalize'; import { XEventsTypes } from '../../../wiring/events.types'; import { WireMetadata } from '../../../wiring/wiring.types'; @@ -10,6 +9,7 @@ import { getDataTestSelector, installNewXPlugin } from '../../../__tests__/utils import BaseSuggestion from '../base-suggestion.vue'; import { createSimpleFacetStub } from '../../../__stubs__/facets-stubs.factory'; import { createPopularSearch } from '../../../__stubs__/popular-searches-stubs.factory'; +import { bus } from '../../../plugins/index'; function renderBaseSuggestion({ query = 'bebe', @@ -17,7 +17,7 @@ function renderBaseSuggestion({ suggestionSelectedEvents = {} }: BaseSuggestionOptions = {}): BaseSuggestionAPI { const [, localVue] = installNewXPlugin(); - const emit = jest.spyOn(XPlugin.bus, 'emit'); + const emit = jest.spyOn(bus, 'emit'); const wrapper = mount( { components: { BaseSuggestion }, @@ -56,6 +56,14 @@ function renderBaseSuggestion({ } describe('testing Base Suggestion component', () => { + beforeAll(() => { + jest.useFakeTimers(); + }); + + beforeEach(() => { + jest.clearAllMocks(); + }); + it('renders a basic suggestion', () => { const { wrapper } = renderBaseSuggestion({ suggestion: createPopularSearch('milk')