From 800871166ce59aa3d2aa13bfbcb798480fc80481 Mon Sep 17 00:00:00 2001 From: Eric Wang Date: Wed, 22 Apr 2020 20:16:03 +1000 Subject: [PATCH] chore: Transform alert test to typescript (#23495) --- .../{demo.test.js.snap => demo.test.ts.snap} | 0 ...index.test.js.snap => index.test.tsx.snap} | 0 .../__tests__/{demo.test.js => demo.test.ts} | 0 .../{index.test.js => index.test.tsx} | 22 ++++++------------- components/alert/index.tsx | 2 ++ 5 files changed, 9 insertions(+), 15 deletions(-) rename components/alert/__tests__/__snapshots__/{demo.test.js.snap => demo.test.ts.snap} (100%) rename components/alert/__tests__/__snapshots__/{index.test.js.snap => index.test.tsx.snap} (100%) rename components/alert/__tests__/{demo.test.js => demo.test.ts} (100%) rename components/alert/__tests__/{index.test.js => index.test.tsx} (88%) diff --git a/components/alert/__tests__/__snapshots__/demo.test.js.snap b/components/alert/__tests__/__snapshots__/demo.test.ts.snap similarity index 100% rename from components/alert/__tests__/__snapshots__/demo.test.js.snap rename to components/alert/__tests__/__snapshots__/demo.test.ts.snap diff --git a/components/alert/__tests__/__snapshots__/index.test.js.snap b/components/alert/__tests__/__snapshots__/index.test.tsx.snap similarity index 100% rename from components/alert/__tests__/__snapshots__/index.test.js.snap rename to components/alert/__tests__/__snapshots__/index.test.tsx.snap diff --git a/components/alert/__tests__/demo.test.js b/components/alert/__tests__/demo.test.ts similarity index 100% rename from components/alert/__tests__/demo.test.js rename to components/alert/__tests__/demo.test.ts diff --git a/components/alert/__tests__/index.test.js b/components/alert/__tests__/index.test.tsx similarity index 88% rename from components/alert/__tests__/index.test.js rename to components/alert/__tests__/index.test.tsx index 209d5c5c00..c5edc6376c 100644 --- a/components/alert/__tests__/index.test.js +++ b/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(); + const wrapper = mount(); 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(); + const wrapper = mount(); const input = wrapper.find('.ant-alert').getDOMNode(); expect(input.getAttribute('aria-describedby')).toBe('some-label'); }); it('sets role attribute on input', () => { - const wrapper = mount(); + const wrapper = mount(); 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 = () => ; 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).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).instance().getPopupDomNode()).toBeTruthy(); jest.useFakeTimers(); }); }); diff --git a/components/alert/index.tsx b/components/alert/index.tsx index 047e6a4fe7..65bcf37924 100755 --- a/components/alert/index.tsx +++ b/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;