Browse Source

chore: Transform alert test to typescript (#23495)

pull/23498/head
Eric Wang 5 years ago
committed by GitHub
parent
commit
800871166c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 0
      components/alert/__tests__/__snapshots__/demo.test.ts.snap
  2. 0
      components/alert/__tests__/__snapshots__/index.test.tsx.snap
  3. 0
      components/alert/__tests__/demo.test.ts
  4. 22
      components/alert/__tests__/index.test.tsx
  5. 2
      components/alert/index.tsx

0
components/alert/__tests__/__snapshots__/demo.test.js.snap → components/alert/__tests__/__snapshots__/demo.test.ts.snap

0
components/alert/__tests__/__snapshots__/index.test.js.snap → components/alert/__tests__/__snapshots__/index.test.tsx.snap

0
components/alert/__tests__/demo.test.js → components/alert/__tests__/demo.test.ts

22
components/alert/__tests__/index.test.js → components/alert/__tests__/index.test.tsx

@ -39,20 +39,20 @@ describe('Alert', () => {
describe('data and aria props', () => {
it('sets data attributes on input', () => {
const wrapper = mount(<Alert data-test="test-id" data-id="12345" />);
const wrapper = mount(<Alert data-test="test-id" data-id="12345" message={null} />);
const input = wrapper.find('.ant-alert').getDOMNode();
expect(input.getAttribute('data-test')).toBe('test-id');
expect(input.getAttribute('data-id')).toBe('12345');
});
it('sets aria attributes on input', () => {
const wrapper = mount(<Alert aria-describedby="some-label" />);
const wrapper = mount(<Alert aria-describedby="some-label" message={null} />);
const input = wrapper.find('.ant-alert').getDOMNode();
expect(input.getAttribute('aria-describedby')).toBe('some-label');
});
it('sets role attribute on input', () => {
const wrapper = mount(<Alert role="status" />);
const wrapper = mount(<Alert role="status" message={null} />);
const input = wrapper.find('.ant-alert').getDOMNode();
expect(input.getAttribute('role')).toBe('status');
});
@ -60,6 +60,8 @@ describe('Alert', () => {
const testIt = process.env.REACT === '15' ? it.skip : it;
testIt('ErrorBoundary', () => {
// TODO: Change to @ts-expect-error once typescript is at 3.9
// @ts-ignore
// eslint-disable-next-line react/jsx-no-undef
const ThrowError = () => <NotExisted />;
const wrapper = mount(
@ -83,12 +85,7 @@ describe('Alert', () => {
);
wrapper.find('.ant-alert').simulate('mouseenter');
await sleep(0);
expect(
wrapper
.find(Tooltip)
.instance()
.getPopupDomNode(),
).toBeTruthy();
expect(wrapper.find<Tooltip>(Tooltip).instance().getPopupDomNode()).toBeTruthy();
jest.useFakeTimers();
});
@ -104,12 +101,7 @@ describe('Alert', () => {
);
wrapper.find('.ant-alert').simulate('click');
await sleep(0);
expect(
wrapper
.find(Popconfirm)
.instance()
.getPopupDomNode(),
).toBeTruthy();
expect(wrapper.find<Popconfirm>(Popconfirm).instance().getPopupDomNode()).toBeTruthy();
jest.useFakeTimers();
});
});

2
components/alert/index.tsx

@ -37,6 +37,8 @@ export interface AlertProps {
afterClose?: () => void;
/** Whether to show icon */
showIcon?: boolean;
/** https://www.w3.org/TR/2014/REC-html5-20141028/dom.html#aria-role-attribute */
role?: string;
style?: React.CSSProperties;
prefixCls?: string;
className?: string;

Loading…
Cancel
Save