Skip to content

Commit 24af229

Browse files
committed
test: Add onChange test case.
1 parent 067a8f8 commit 24af229

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

test/index.test.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable jest/no-conditional-expect */
22
import React, { useEffect, useRef } from 'react';
33
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';
56
// import '@testing-library/jest-dom';
67
// import userEvent from '@testing-library/user-event';
78
import CodeMirror, { ReactCodeMirrorRef } from '../src';
@@ -16,16 +17,17 @@ it('CodeMirror', async () => {
1617
});
1718

1819
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} />,
2726
);
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');
2931
});
3032

3133
it('CodeMirror onUpdate', async () => {

0 commit comments

Comments
 (0)