From 24af2291d632759da7e270502fc692e2836eba2e Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Thu, 14 Oct 2021 14:22:28 +0800 Subject: [PATCH] test: Add onChange test case. --- test/index.test.tsx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/test/index.test.tsx b/test/index.test.tsx index 6ee186b25..8282064e9 100644 --- a/test/index.test.tsx +++ b/test/index.test.tsx @@ -1,7 +1,8 @@ /* eslint-disable jest/no-conditional-expect */ import React, { useEffect, useRef } from 'react'; import renderer from 'react-test-renderer'; -import { render } from '@testing-library/react'; +import { render, fireEvent } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; // import '@testing-library/jest-dom'; // import userEvent from '@testing-library/user-event'; import CodeMirror, { ReactCodeMirrorRef } from '../src'; @@ -16,16 +17,17 @@ it('CodeMirror', async () => { }); it('CodeMirror onChange', async () => { - render( - { - expect(value).toEqual(`console.log('Hello world!')`); - }} - />, + const handleChange = jest.fn((value) => { + expect(value).toEqual('# title'); + return Array.isArray(value) ? value.join() : value; + }); + const { findByRole, queryByText } = render( + , ); - // const cont = document.querySelector('.cm-content'); + const input = await findByRole('textbox'); + fireEvent.change(input, { target: { textContent: '# title' } }); + const elm = queryByText('# title'); + expect((elm as any).cmView.dom.innerHTML).toEqual('# title'); }); it('CodeMirror onUpdate', async () => {