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
fix: Conformance tests should unmount components #21423
Changes from all 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "fix: Conformance tests should unmount components", | ||
"packageName": "@fluentui/react-conformance", | ||
"email": "lingfangao@hotmail.com", | ||
"dependentChangeType": "patch" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { mount as enzymeMount, ReactWrapper } from 'enzyme'; | ||
|
||
let wrapper: ReactWrapper | undefined; | ||
|
||
/** | ||
* A wrapper around enzyme's mount that helps with unmounting and cleanup | ||
* This is an approach that's adopted by quite a few users of enzyme. | ||
* https://github.com/enzymejs/enzyme/issues/911 | ||
* @returns Enzyme wrapper | ||
*/ | ||
export const mount = (...args: Parameters<typeof enzymeMount>) => { | ||
const enzymeWrapper = enzymeMount(...args); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
wrapper = enzymeWrapper; | ||
Comment on lines
+13
to
+15
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. Why it's not assignable? 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. enzyme 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. Can you cast instead of ts-ignore so it's less "nuclear"? |
||
return enzymeWrapper; | ||
}; | ||
|
||
export const cleanup = () => { | ||
if (wrapper) { | ||
wrapper.unmount(); | ||
} | ||
|
||
wrapper = undefined; | ||
}; |
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.
The odd test that calls
mount
more than once. This kind of test cannot be used with a 'global' mount.I think this is 🤮 but can't think of a better, idea. Suggestions welcome
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.
A bit confused, where's the other call? Also not quite understanding what the problem is (but I also don't have a deep understanding of how
mount
works withoutattachTo
).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 created a
mountWithCleanup
module which is generally how the enzyme community seems to handle the unmounting, however that solution breaks down whenmount
is used more than once in a test.Unfortunately, this is the only time in all conformance tests this is done. The alternative would be to explicitly unmount in each test.
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.
Ah now I see the second
mount
below this one. I'm still not convinced this is a problem given that the test is comparing classNames in two different cases, but theoretically you could do the same thing by mounting the component once and updating props. Or to be certain of avoiding interference/retained state, maybe the test could mount both versions at once inside a fragment?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.
yeah that's a good shout, I'll try to update the test to use a single mount