Skip to content

Commit

Permalink
fix(react): fix extend expect
Browse files Browse the repository at this point in the history
  • Loading branch information
brionmario committed Feb 9, 2023
1 parent dbe4242 commit 5e18991
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
"typecheck": "tsc --noemit -p tsconfig.json"
},
"dependencies": {
"@oxygen-ui/react-icons": "*",
"@oxygen-ui/primitives": "*",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@mui/icons-material": "^5.10.16",
"@mui/lab": "5.0.0-alpha.110",
"@mui/material": "^5.10.16",
"@mui/system": "^5.10.16",
"@mui/utils": "^5.10.16",
"@oxygen-ui/primitives": "*",
"@oxygen-ui/react-icons": "*",
"clsx": "^1.2.1"
},
"devDependencies": {
Expand Down Expand Up @@ -71,6 +71,7 @@
"@types/node": "^18.11.18",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@types/testing-library__jest-dom": "^5.14.5",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?b46eeeeaa9365277e46aa3b3b6dee339a78f4b3e",
"@wso2/prettier-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?b46eeeeaa9365277e46aa3b3b6dee339a78f4b3e",
"babel-jest": "^29.3.1",
Expand Down
18 changes: 16 additions & 2 deletions packages/react/src/components/Button/__tests__/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* under the License.
*/

import React from 'react';
import {render} from '@unit-testing';
import React, {MouseEventHandler} from 'react';
import {fireEvent, render, screen} from '@unit-testing';
import Button from '../Button';

describe('Button', () => {
Expand All @@ -30,4 +30,18 @@ describe('Button', () => {
const {baseElement} = render(<Button />);
expect(baseElement).toMatchSnapshot();
});

it('should render text correctly', () => {
render(<Button>Oxygen UI Button</Button>);
const element: HTMLButtonElement = screen.getByText('Oxygen UI Button');
expect(element).toHaveTextContent('Oxygen UI Button');
});

it('should should handle onClick event', () => {
const onClick: MouseEventHandler<HTMLButtonElement> = jest.fn();
render(<Button onClick={onClick}>Oxygen UI Button</Button>);
const element: HTMLButtonElement = screen.getByText('Oxygen UI Button');
fireEvent.click(element);
expect(onClick).toHaveBeenCalledTimes(1);
});
});
2 changes: 1 addition & 1 deletion packages/react/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node", "@testing-library/jest-dom"]
},
"include": [
"test-configs",
Expand Down

0 comments on commit 5e18991

Please sign in to comment.