Skip to content

Commit efbb062

Browse files
Prefer user.keyboard() for JSDOM text entry
1 parent d8f33c5 commit efbb062

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

packages/nhsuk-frontend/src/nhsuk/components/character-count/character-count.jsdom.test.mjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { getByRole } from '@testing-library/dom'
2+
import { userEvent } from '@testing-library/user-event'
23
import { outdent } from 'outdent'
34

45
import { CharacterCount, initCharacterCounts } from './character-count.mjs'
56
import { examples } from './fixtures.mjs'
67

78
import { components } from '#lib'
89

10+
const user = userEvent.setup()
11+
912
describe('Character count', () => {
1013
/** @type {HTMLElement} */
1114
let $root
@@ -350,12 +353,13 @@ describe('Character count', () => {
350353
expect(component.getCountMessage()).toBe('You have 98 words remaining')
351354
})
352355

353-
it('uses current textarea value for `maxlength` limit via back/forward navigation', () => {
356+
it('uses current textarea value for `maxlength` limit via back/forward navigation', async () => {
354357
const component = new CharacterCount($root, {
355358
maxlength: 100
356359
})
357360

358-
$textarea.value = 'Newly updated value'
361+
$textarea.focus()
362+
await user.keyboard('Newly updated value')
359363

360364
// Trigger back/forward navigation
361365
window.dispatchEvent(
@@ -369,12 +373,13 @@ describe('Character count', () => {
369373
)
370374
})
371375

372-
it('uses current textarea value for `maxwords` limit via back/forward navigation', () => {
376+
it('uses current textarea value for `maxwords` limit via back/forward navigation', async () => {
373377
const component = new CharacterCount($root, {
374378
maxwords: 100
375379
})
376380

377-
$textarea.value = 'Newly updated value'
381+
$textarea.focus()
382+
await user.keyboard('Newly updated value')
378383

379384
// Trigger back/forward navigation
380385
window.dispatchEvent(

0 commit comments

Comments
 (0)