-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: Specify baseElement without container #394
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 2 commits
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 |
|---|---|---|
|
|
@@ -113,3 +113,44 @@ test('renders options.wrapper around node', () => { | |
| </div> | ||
| `) | ||
| }) | ||
|
|
||
| describe('baseElement', () => { | ||
| let baseElement | ||
| beforeAll(() => { | ||
| baseElement = document.createElement('div') | ||
| document.body.appendChild(baseElement) | ||
| }) | ||
|
|
||
| afterAll(() => { | ||
| baseElement.parentNode.removeChild(baseElement) | ||
| }) | ||
|
|
||
| it('can take a custom element for isolation', () => { | ||
| function DescribedButton({title: description, ...buttonProps}) { | ||
|
||
| return ( | ||
| <React.Fragment> | ||
| <button {...buttonProps} aria-describedby="tooltip" /> | ||
| {ReactDOM.createPortal( | ||
| <div id="tooltip" role="tooltip"> | ||
| {description} | ||
| </div>, | ||
| document.body, | ||
| )} | ||
| </React.Fragment> | ||
| ) | ||
| } | ||
|
|
||
| const {getByRole, getByText} = render( | ||
| <DescribedButton description="this descripton is hidden from rtl"> | ||
| Click me | ||
| </DescribedButton>, | ||
| {baseElement}, | ||
| ) | ||
|
|
||
| expect(getByText('Click me')).toBeTruthy() | ||
| expect(document.querySelector('[role="tooltip"]')).toBeTruthy() | ||
| expect(() => getByRole('tooltip')).toThrow( | ||
| 'Unable to find an element by [role=tooltip]', | ||
| ) | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really prefer to not use any nesting. This is all for just one test, please instead move the contents of beforeAll and afterAll to the inside of the test and use the
testglobal rather than thedescribeanditglobals.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks two other test that assume an empty body. The nesting is for isolation. What is the problem with that? The alternative is to create a new test which is worse IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the direction that nesting puts us in. It's a slippery slope IMO. Maybe I'm just too scarred by past testbases. I'm much more willing to create a new test file than nesting tests.
Another thing we could do is just take the
beforeAllandafterAlland put them inside the test. That would avoid the problems altogether. Could you do that please?