diff --git a/packages/editor-ui/src/__tests__/utils.ts b/packages/editor-ui/src/__tests__/utils.ts index 9ae18517fe..d7ff2e3586 100644 --- a/packages/editor-ui/src/__tests__/utils.ts +++ b/packages/editor-ui/src/__tests__/utils.ts @@ -4,10 +4,15 @@ import type { ISettingsState } from '@/Interface'; import { UserManagementAuthenticationMethod } from '@/Interface'; import { defaultSettings } from './defaults'; -export const retry = async ( - assertion: () => ReturnType, - { interval = 20, timeout = 1000 } = {}, -) => { +/** + * Retries the given assertion until it passes or the timeout is reached + * + * @example + * await retry( + * () => expect(screen.getByText('Hello')).toBeInTheDocument() + * ); + */ +export const retry = async (assertion: () => void, { interval = 20, timeout = 1000 } = {}) => { return await new Promise((resolve, reject) => { const startTime = Date.now(); @@ -15,9 +20,9 @@ export const retry = async ( setTimeout(() => { try { resolve(assertion()); - } catch (err) { + } catch (error) { if (Date.now() - startTime > timeout) { - reject(err); + reject(error); } else { tryAgain(); } diff --git a/packages/editor-ui/src/components/__tests__/PersonalizationModal.spec.ts b/packages/editor-ui/src/components/__tests__/PersonalizationModal.spec.ts index 3ab834b20e..4716eac590 100644 --- a/packages/editor-ui/src/components/__tests__/PersonalizationModal.spec.ts +++ b/packages/editor-ui/src/components/__tests__/PersonalizationModal.spec.ts @@ -73,6 +73,7 @@ describe('PersonalizationModal.vue', () => { ); for (const index of [3, 4, 5, 6]) { + const expectFn = expect; // So we don't break @typescript-eslint/no-loop-func const select = wrapper.container.querySelectorAll('.n8n-select')[1]; await fireEvent.click(select); @@ -82,8 +83,8 @@ describe('PersonalizationModal.vue', () => { await fireEvent.click(item); await retry(() => { - expect(wrapper.container.querySelectorAll('.n8n-select').length).toEqual(6); - expect(wrapper.container.querySelector('[name^="automationGoal"]')).toBeInTheDocument(); + expectFn(wrapper.container.querySelectorAll('.n8n-select').length).toEqual(6); + expectFn(wrapper.container.querySelector('[name^="automationGoal"]')).toBeInTheDocument(); }); } }); @@ -125,7 +126,8 @@ describe('PersonalizationModal.vue', () => { const item = select.querySelectorAll('.el-select-dropdown__item')[3]; await fireEvent.click(item); - const agreeCheckbox = wrapper.container.querySelector('.n8n-checkbox')!; + const agreeCheckbox = wrapper.container.querySelector('.n8n-checkbox'); + assert(agreeCheckbox); await fireEvent.click(agreeCheckbox); const submitButton = wrapper.getByRole('button');