Skip to content

Commit

Permalink
fix: use @testing-library/userEvent for broken tests following preact…
Browse files Browse the repository at this point in the history
… update

Reason the tests failed: preactjs/preact#3354
  • Loading branch information
Skaiir committed Sep 29, 2024
1 parent 0a68bd5 commit 568c04a
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 148 deletions.
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@svgr/rollup": "^8.1.0",
"@svgr/webpack": "^8.1.0",
"@testing-library/preact": "^3.2.3",
"@testing-library/user-event": "^14.5.2",
"@types/chai": "^4.3.19",
"@types/mocha": "^10.0.8",
"@types/node": "^22.7.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/form-js-viewer/test/spec/Form.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, fireEvent, screen, waitFor } from '@testing-library/preact/pure';
import userEvent from '@testing-library/user-event';

import { createForm, Form, schemaVersion } from '../../src';

Expand Down Expand Up @@ -666,12 +667,11 @@ describe('Form', function () {
const elements = container.querySelector('.fjs-element').querySelectorAll('.fjs-element');
const element = elements[index];
const focusTarget = element.querySelector(selector);
const formRoot = container.querySelector('.fjs-form');

// when
await act(() => {
fireEvent.focus(focusTarget);
fireEvent.blur(focusTarget);
});
await userEvent.click(focusTarget);
await userEvent.click(formRoot);

// then
expect(focusSpy).to.have.been.calledWithMatch({ formField });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fireEvent, render } from '@testing-library/preact/pure';
import userEvent from '@testing-library/user-event';

import { classes } from 'min-dom';

Expand Down Expand Up @@ -266,8 +267,8 @@ describe('FormField', function () {
});

describe('eager validation', function () {
it('should trigger validation on blur', function () {
// when
it('should trigger validation on blur', async function () {
// given
const setStateSpy = sinon.spy();
const { container } = createFormField({
field: {
Expand All @@ -277,15 +278,17 @@ describe('FormField', function () {
validationErrors: ['validation-error'],
});

// then
const formField = container.querySelector('.fjs-form-field');
expect(formField).to.exist;

const input = container.querySelector('input[type="text"]');
expect(setStateSpy).not.to.have.been.called;

// when
await userEvent.click(input);
await userEvent.tab();

// then
fireEvent.blur(input);
expect(setStateSpy).to.have.been.calledWith({
errors: {
Creditor_ID: ['validation-error'],
Expand Down
Loading

0 comments on commit 568c04a

Please sign in to comment.