Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ lib
es
coverage
yarn.lock
package-lock.json


# dumi
Expand Down
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import * as React from 'react';
import { forwardRef, useImperativeHandle, useRef } from 'react';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import classNames from 'classnames';

export interface CheckboxChangeEvent {
target: CheckboxChangeEventTarget;
Expand Down
58 changes: 58 additions & 0 deletions tests/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`rc-checkbox click checkbox 1`] = `
<span
class="rc-checkbox"
>
<input
class="rc-checkbox-input"
type="checkbox"
/>
<span
class="rc-checkbox-inner"
/>
</span>
`;

exports[`rc-checkbox click radio 1`] = `
<span
class="rc-checkbox rc-checkbox-checked"
>
<input
class="rc-checkbox-input"
type="radio"
/>
<span
class="rc-checkbox-inner"
/>
</span>
`;

exports[`rc-checkbox control mode 1`] = `
<span
class="rc-checkbox rc-checkbox-checked"
>
<input
checked=""
class="rc-checkbox-input"
type="checkbox"
/>
<span
class="rc-checkbox-inner"
/>
</span>
`;

exports[`rc-checkbox works 1`] = `
<span
class="rc-checkbox"
>
<input
class="rc-checkbox-input"
type="checkbox"
/>
<span
class="rc-checkbox-inner"
/>
</span>
`;
9 changes: 6 additions & 3 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import KeyCode from 'rc-util/lib/KeyCode';
import { fireEvent, render } from '@testing-library/react';
import KeyCode from 'rc-util/lib/KeyCode';
import * as React from 'react';
import Checkbox from '../src';

import type { CheckboxRef } from '../src';
Expand All @@ -17,6 +17,7 @@ describe('rc-checkbox', () => {

fireEvent.click(inputEl);
expect(inputEl.checked).toBe(false);
expect(container.firstChild).toMatchSnapshot();
});

it('click radio', () => {
Expand All @@ -30,6 +31,7 @@ describe('rc-checkbox', () => {

fireEvent.click(inputEl);
expect(inputEl.checked).toBe(true);
expect(container.firstChild).toMatchSnapshot();
});

it('click checkbox', () => {
Expand All @@ -43,6 +45,7 @@ describe('rc-checkbox', () => {

fireEvent.click(inputEl);
expect(inputEl.checked).toBe(false);
expect(container.firstChild).toMatchSnapshot();
});

it('control mode', () => {
Expand All @@ -56,6 +59,7 @@ describe('rc-checkbox', () => {

fireEvent.click(inputEl);
expect(inputEl.checked).toBe(true);
expect(container.firstChild).toMatchSnapshot();
});

it('stopPropagation and preventDefault', () => {
Expand Down Expand Up @@ -93,7 +97,6 @@ describe('rc-checkbox', () => {
});

it('passes role prop to input', () => {
// eslint-disable-next-line jsx-a11y/aria-role
const { container } = render(<Checkbox role="my-role" />);
const inputEl = container.querySelector('input')!;

Expand Down