-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: replace use of enzyme with react-testing-library #1144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3c4ee46
e3ffa8b
017695a
817d304
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
*/ | ||
|
||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
import FieldDoc from '../FieldDoc'; | ||
|
||
|
@@ -35,47 +36,58 @@ const exampleObject = new GraphQLObjectType({ | |
|
||
describe('FieldDoc', () => { | ||
it('should render a simple string field', () => { | ||
const W = mount( | ||
const { container } = render( | ||
<FieldDoc | ||
field={exampleObject.getFields().string} | ||
onClickType={jest.fn()} | ||
/>, | ||
); | ||
expect(W.find('MarkdownContent').text()).toEqual('No Description\n'); | ||
expect(W.find('TypeLink').text()).toEqual('String'); | ||
expect(W.find('Argument').length).toEqual(0); | ||
expect(container.querySelector('.doc-type-description')).toHaveTextContent( | ||
'No Description', | ||
); | ||
expect(container.querySelector('.type-name')).toHaveTextContent('String'); | ||
expect(container.querySelector('.arg')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should re-render on field change', () => { | ||
const W = mount( | ||
const { container, rerender } = render( | ||
<FieldDoc | ||
field={exampleObject.getFields().string} | ||
onClickType={jest.fn()} | ||
/>, | ||
); | ||
expect(W.find('MarkdownContent').text()).toEqual('No Description\n'); | ||
expect(W.find('TypeLink').text()).toEqual('String'); | ||
expect(W.find('Argument').length).toEqual(0); | ||
expect(container.querySelector('.doc-type-description')).toHaveTextContent( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm worried about how stable it will be using classes instead of component names as before, especially since we are about to change how layout/theming works and use theme-ui/emotion/etc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm yeah, I wasn't to keen on using querySelector but I was trying to avoid making any changes to non-test code. Do you think it's worth adding either labels or testids to the components? We mostly just use a lot of classes in these components and react-testing-library doesn't let you target react implementation code |
||
'No Description', | ||
); | ||
expect(container.querySelector('.type-name')).toHaveTextContent('String'); | ||
expect(container.querySelector('.arg')).not.toBeInTheDocument(); | ||
|
||
rerender( | ||
<FieldDoc | ||
field={exampleObject.getFields().stringWithArgs} | ||
onClickType={jest.fn()} | ||
/>, | ||
); | ||
expect(container.querySelector('.type-name')).toHaveTextContent('String'); | ||
expect(container.querySelector('.doc-type-description')).toHaveTextContent( | ||
'Example String field with arguments', | ||
); | ||
}); | ||
|
||
it('should render a string field with arguments', () => { | ||
const W = mount( | ||
const { container } = render( | ||
<FieldDoc | ||
field={exampleObject.getFields().stringWithArgs} | ||
onClickType={jest.fn()} | ||
/>, | ||
); | ||
expect( | ||
W.find('TypeLink') | ||
.at(0) | ||
.text(), | ||
).toEqual('String'); | ||
expect( | ||
W.find('.doc-type-description') | ||
.at(0) | ||
.text(), | ||
).toEqual('Example String field with arguments\n'); | ||
expect(W.find('Argument').length).toEqual(1); | ||
expect(W.find('Argument').text()).toEqual('stringArg: String'); | ||
expect(container.querySelector('.type-name')).toHaveTextContent('String'); | ||
expect(container.querySelector('.doc-type-description')).toHaveTextContent( | ||
'Example String field with arguments', | ||
); | ||
expect(container.querySelectorAll('.arg')).toHaveLength(1); | ||
expect(container.querySelector('.arg')).toHaveTextContent( | ||
'stringArg: String', | ||
); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.