From 6b21fe2bacf21b3e3863f3dadda33b019b55b331 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Wed, 1 Dec 2021 10:24:03 -0500 Subject: [PATCH] Fixed test that breaks once upgraded to Node 16. (#15621) --- .../shared/components/__tests__/tags.test.jsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/javascript/shared/components/__tests__/tags.test.jsx b/app/javascript/shared/components/__tests__/tags.test.jsx index 3118b2856..0929fbebc 100644 --- a/app/javascript/shared/components/__tests__/tags.test.jsx +++ b/app/javascript/shared/components/__tests__/tags.test.jsx @@ -4,11 +4,14 @@ import { render, fireEvent } from '@testing-library/preact'; import { axe } from 'jest-axe'; import { Tags } from '../tags'; +fetch.enableMocks(); + describe('', () => { beforeAll(() => { const environment = document.createElement('meta'); environment.setAttribute('name', 'environment'); document.body.appendChild(environment); + fetch.resetMocks(); window.fetch = fetch; }); @@ -21,6 +24,10 @@ describe('', () => { describe('handleKeyDown', () => { it('does not call preventDefault on used keyCode', () => { + // Only one call is being made to /tags/suggest when the comma key is pressed + // It didn't seem worth it to inspect the whole mock object to ensure the right URL etc. + fetch.mockResponseOnce('[]'); + const { getByTestId } = render( , ); @@ -34,8 +41,10 @@ describe('', () => { { key: 'Enter', code: '13' }, ]; + const input = getByTestId('tag-input'); + tests.forEach((eventPayload) => { - fireEvent.keyDown(getByTestId('tag-input'), eventPayload); + fireEvent.keyDown(input, eventPayload); }); expect(Event.prototype.preventDefault).not.toHaveBeenCalled();