Skip to content

Commit

Permalink
test: fix test case issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Sep 22, 2023
1 parent c08032b commit c726659
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
17 changes: 9 additions & 8 deletions core/src/__test__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable jest/no-conditional-expect */
import React, { useEffect, useRef } from 'react';
import TestRenderer from 'react-test-renderer';
import { fireEvent, render, screen } from '@testing-library/react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import TextareaCodeEditor from '../';
Expand Down Expand Up @@ -180,13 +179,15 @@ it('TextareaCodeEditor onKeyDown Tab Input', async () => {
const elmTextarea = screen.getByDisplayValue('This is a bad example');
(elmTextarea as HTMLTextAreaElement).setSelectionRange(1, 1);
elmTextarea.focus();
await userEvent.keyboard('a');
expect(onKeyDown).toHaveBeenCalledTimes(1);
// expect(onKeyDown.mock.calls[0][0]).toHaveProperty('keyCode', 97);
await waitFor(async () => {
await userEvent.keyboard('a');
expect(onKeyDown).toHaveBeenCalledTimes(1);
// expect(onKeyDown.mock.calls[0][0]).toHaveProperty('keyCode', 97);
await userEvent.keyboard('[Enter]');
expect(onKeyDown).toHaveBeenCalledTimes(2);
// expect(onKeyDown.mock.calls[1][0]).toHaveProperty('keyCode', 13);
});

await userEvent.keyboard('[Enter]');
expect(onKeyDown).toHaveBeenCalledTimes(2);
// expect(onKeyDown.mock.calls[1][0]).toHaveProperty('keyCode', 13);
elmTextarea.focus();
expect(elmTextarea).toHaveValue('Ta\nhis is a bad example');

Expand Down
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"doc": "lerna exec --scope website -- npm run build",
"bundle": "lerna exec --scope @uiw/react-textarea-code-editor -- ncc build src/index.tsx --target web --filename editor",
"bundle:min": "lerna exec --scope @uiw/react-textarea-code-editor -- ncc build src/index.tsx --target web --filename editor --minify",
"test": "lerna exec --scope @uiw/react-textarea-code-editor -- tsbb test --env=jsdom",
"coverage": "lerna exec --scope @uiw/react-textarea-code-editor -- tsbb test --env=jsdom --coverage --bail",
"test": "lerna exec --scope @uiw/react-textarea-code-editor -- tsbb test",
"coverage": "lerna exec --scope @uiw/react-textarea-code-editor -- tsbb test --coverage --bail",
"prepare": "husky install",
"publish": "lerna publish from-package --yes --no-verify-access",
"version": "lerna version --exact --force-publish --no-push --no-git-tag-version",
Expand All @@ -35,17 +35,13 @@
"@kkt/scope-plugin-options": "^7.5.2",
"@kkt/less-modules": "^7.5.2",
"@kkt/ncc": "^1.0.14",
"compile-less-cli": "^1.8.14",
"compile-less-cli": "^1.9.0",
"husky": "^8.0.3",
"jest": "^29.5.0",
"jest-watch-typeahead": "^2.2.2",
"jest-environment-jsdom": "~29.5.0",
"jest-environment-node": "^29.5.0",
"kkt": "^7.5.2",
"lint-staged": "^14.0.0",
"lerna": "^7.1.3",
"prettier": "^3.0.0",
"react-test-renderer": "^18.2.0",
"tsbb": "^4.1.14"
"tsbb": "^4.2.1"
}
}
2 changes: 1 addition & 1 deletion www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@uiw/react-textarea-code-editor": "2.1.7",
"@uiw/react-markdown-preview-example": "^1.3.1",
"@uiw/react-markdown-preview-example": "^1.5.7",
"@uiw/react-loader": "^4.21.14",
"styled-components": "^6.0.5",
"code-example": "^3.3.6",
Expand Down

0 comments on commit c726659

Please sign in to comment.