1
1
/* eslint-disable jest/no-conditional-expect */
2
2
import React , { useEffect , useRef } from 'react' ;
3
3
import renderer from 'react-test-renderer' ;
4
- import { render } from '@testing-library/react' ;
4
+ import { render , fireEvent } from '@testing-library/react' ;
5
+ import userEvent from '@testing-library/user-event' ;
5
6
// import '@testing-library/jest-dom';
6
7
// import userEvent from '@testing-library/user-event';
7
8
import CodeMirror , { ReactCodeMirrorRef } from '../src' ;
@@ -16,16 +17,17 @@ it('CodeMirror', async () => {
16
17
} ) ;
17
18
18
19
it ( 'CodeMirror onChange' , async ( ) => {
19
- render (
20
- < CodeMirror
21
- autoFocus
22
- value = "console.log('Hello world!')"
23
- onChange = { ( value ) => {
24
- expect ( value ) . toEqual ( `console.log('Hello world!')` ) ;
25
- } }
26
- /> ,
20
+ const handleChange = jest . fn ( ( value ) => {
21
+ expect ( value ) . toEqual ( '# title' ) ;
22
+ return Array . isArray ( value ) ? value . join ( ) : value ;
23
+ } ) ;
24
+ const { findByRole, queryByText } = render (
25
+ < CodeMirror autoFocus value = "console.log('Hello world!')" onChange = { handleChange } /> ,
27
26
) ;
28
- // const cont = document.querySelector('.cm-content');
27
+ const input = await findByRole ( 'textbox' ) ;
28
+ fireEvent . change ( input , { target : { textContent : '# title' } } ) ;
29
+ const elm = queryByText ( '# title' ) ;
30
+ expect ( ( elm as any ) . cmView . dom . innerHTML ) . toEqual ( '# title' ) ;
29
31
} ) ;
30
32
31
33
it ( 'CodeMirror onUpdate' , async ( ) => {
0 commit comments