11import { useState } from 'react' ;
2- import { fireEvent , render , screen } from '@testing-library/react ' ;
3- import userEvent from '@testing-library/user-event ' ;
2+ import { userEvent } from '@vitest/browser/context ' ;
3+ import { render } from 'vitest-browser-react ' ;
44
55import DataGrid , { textEditor } from '../../src' ;
66import type { Column } from '../../src' ;
@@ -10,7 +10,16 @@ interface Row {
1010 readonly name : string ;
1111}
1212
13- const columns : readonly Column < Row > [ ] = [ { key : 'name' , name : 'Name' , renderEditCell : textEditor } ] ;
13+ const columns : readonly Column < Row > [ ] = [
14+ {
15+ key : 'name' ,
16+ name : 'Name' ,
17+ renderEditCell : textEditor ,
18+ editorOptions : {
19+ commitOnOutsideClick : false
20+ }
21+ }
22+ ] ;
1423const initialRows : readonly Row [ ] = [ { name : 'Tacitus Kilgore' } ] ;
1524
1625function Test ( ) {
@@ -20,10 +29,10 @@ function Test() {
2029}
2130
2231test ( 'TextEditor' , async ( ) => {
23- render ( < Test /> ) ;
32+ const screen = render ( < Test /> ) ;
2433
2534 await userEvent . dblClick ( getCells ( ) [ 0 ] ) ;
26- let input : HTMLInputElement | null = screen . getByRole < HTMLInputElement > ( 'textbox' ) ;
35+ let input = screen . getByRole ( 'textbox' ) . element ( ) as HTMLInputElement ;
2736 expect ( input ) . toHaveClass ( 'rdg-text-editor' ) ;
2837 // input value is row[column.key]
2938 expect ( input ) . toHaveValue ( initialRows [ 0 ] . name ) ;
@@ -40,9 +49,9 @@ test('TextEditor', async () => {
4049
4150 // blurring the input closes and commits the editor
4251 await userEvent . dblClick ( getCells ( ) [ 0 ] ) ;
43- input = screen . getByRole < HTMLInputElement > ( 'textbox' ) ;
52+ input = screen . getByRole ( 'textbox' ) . element ( ) as HTMLInputElement ;
4453 await userEvent . keyboard ( 'Jim Milton' ) ;
45- fireEvent . blur ( input ) ;
46- expect ( input ) . not . toBeInTheDocument ( ) ;
54+ await userEvent . tab ( ) ;
55+ await expect . element ( input ) . not . toBeInTheDocument ( ) ;
4756 expect ( getCells ( ) [ 0 ] ) . toHaveTextContent ( / ^ J i m M i l t o n $ / ) ;
4857} ) ;
0 commit comments