-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(react): upgrade to react 17 and remove enzyme
- add react-testing-library - upgrade jest/jsdom dependencies Signed-off-by: Ashley Ryan <asryan@vmware.com>
- Loading branch information
Ashley Ryan
committed
Mar 18, 2022
1 parent
8eef59a
commit 0d00cd7
Showing
92 changed files
with
2,681 additions
and
4,250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
import * as enzyme from 'enzyme'; | ||
import * as Adapter from 'enzyme-adapter-react-16'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
enzyme.configure({ adapter: new Adapter() }); | ||
if (typeof window !== 'undefined') { | ||
// jsdom doesn't implment IntersectionObserver | ||
// https://github.com/jsdom/jsdom/issues/2032 | ||
const mockObserverAPI = () => | ||
jest.fn().mockReturnValue({ | ||
observe: jest.fn(), | ||
unobserve: jest.fn(), | ||
disconnect: jest.fn(), | ||
}); | ||
|
||
window.ResizeObserver = mockObserverAPI(); | ||
window.IntersectionObserver = mockObserverAPI(); | ||
|
||
// jsdom implements getBoundingClientRect, but not DOMRect | ||
if (!window.DOMRect) { | ||
const domRectMock = () => jest.fn().mockReturnValue({}); | ||
window.DOMRect = (domRectMock() as unknown) as typeof window.DOMRect; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,32 @@ | ||
import * as React from 'react'; | ||
import { mount, shallow } from 'enzyme'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { CdsAccordion, CdsAccordionPanel, CdsAccordionHeader, CdsAccordionContent } from './index'; | ||
|
||
describe('CdsAccordion', () => { | ||
it('renders', () => { | ||
const wrapper = shallow( | ||
<div> | ||
<CdsAccordion> | ||
<CdsAccordionPanel expanded> | ||
<CdsAccordionHeader>Item 1</CdsAccordionHeader> | ||
<CdsAccordionContent>Content 1</CdsAccordionContent> | ||
</CdsAccordionPanel> | ||
</CdsAccordion> | ||
</div> | ||
it('renders', async () => { | ||
render( | ||
<CdsAccordion> | ||
<CdsAccordionPanel expanded> | ||
<CdsAccordionHeader>Item 1</CdsAccordionHeader> | ||
<CdsAccordionContent>Content 1</CdsAccordionContent> | ||
</CdsAccordionPanel> | ||
</CdsAccordion> | ||
); | ||
const renderedComponent = wrapper.find(CdsAccordion); | ||
expect(renderedComponent.at(0).html()).toMatch(/Item 1/); | ||
expect(renderedComponent.at(0).html()).toMatch(/Content 1/); | ||
|
||
expect(await document.querySelector('cds-accordion')).toBeInTheDocument(); | ||
expect(await screen.findByText(/item 1/i)).toBeInTheDocument(); | ||
expect(await screen.findByText(/content 1/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('snapshot', () => { | ||
const wrapper = mount( | ||
<div> | ||
<CdsAccordion> | ||
<CdsAccordionPanel expanded> | ||
<CdsAccordionHeader>Item 1</CdsAccordionHeader> | ||
<CdsAccordionContent>Content 1</CdsAccordionContent> | ||
</CdsAccordionPanel> | ||
</CdsAccordion> | ||
</div> | ||
const { container } = render( | ||
<CdsAccordion> | ||
<CdsAccordionPanel expanded> | ||
<CdsAccordionHeader id="my-header">Item 1</CdsAccordionHeader> | ||
<CdsAccordionContent id="my-content">Content 1</CdsAccordionContent> | ||
</CdsAccordionPanel> | ||
</CdsAccordion> | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.