-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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(render): Default to HTMLElement in returned container #868
Changes from 1 commit
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ export async function testRender() { | |
|
||
// helpers | ||
const {container, rerender, debug} = page | ||
expectType<HTMLElement, typeof container>(container) | ||
return {container, rerender, debug} | ||
} | ||
|
||
|
@@ -35,13 +36,18 @@ export async function testPureRender() { | |
|
||
// helpers | ||
const {container, rerender, debug} = page | ||
expectType<HTMLElement, typeof container>(container) | ||
return {container, rerender, debug} | ||
} | ||
|
||
export function testRenderOptions() { | ||
const container = document.createElement('div') | ||
const options = {container} | ||
render(<div />, options) | ||
const {container: returnedContainer} = render(<div />, options) | ||
// Unclear why TypeScript infers `HTMLElement` here when the the input `container` is `HTMLDivElement` | ||
// Hopefully this breaks someday and we can switch to | ||
// expectType<HTMLDivElement, typeof returnedContainer>(returnedContainer) | ||
expectType<HTMLElement, typeof returnedContainer>(returnedContainer) | ||
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. This is a limitation of TypeScript's JSX syntax support. JSX elements unfortunately can't be inferred to a specific element type. You'd have to use the So for now, this test is accurate, though you could avoid JSX if you wanted to still test the regression. 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. The The confusing part is why it works for Let me replace 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. Hm, I missed that, I'm curious what happens 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. Changed. Is it now clearer that the |
||
} | ||
|
||
export function testSVGRenderOptions() { | ||
|
@@ -50,7 +56,8 @@ export function testSVGRenderOptions() { | |
'svg', | ||
) | ||
const options = {container} | ||
render(<svg />, options) | ||
const {container: returnedContainer} = render(<svg />, options) | ||
expectType<SVGSVGElement, typeof returnedContainer>(returnedContainer) | ||
} | ||
|
||
export function testFireEvent() { | ||
|
@@ -87,3 +94,27 @@ eslint | |
testing-library/no-debug: "off", | ||
testing-library/prefer-screen-queries: "off" | ||
*/ | ||
|
||
// https://stackoverflow.com/questions/53807517/how-to-test-if-two-types-are-exactly-the-same | ||
type IfEquals<T, U, Yes = unknown, No = never> = (<G>() => G extends T | ||
? 1 | ||
: 2) extends <G>() => G extends U ? 1 : 2 | ||
? Yes | ||
: No | ||
|
||
/** | ||
* Issues a type error if `Expected` is not identical to `Actual`. | ||
* | ||
* `Expected` should be declared when invoking `expectType`. | ||
* `Actual` should almost always we be a `typeof value` statement. | ||
* | ||
* Source: https://github.com/mui-org/material-ui/blob/6221876a4b468a3330ffaafa8472de7613933b87/packages/material-ui-types/index.d.ts#L73-L84 | ||
* | ||
* @example `expectType<number | string, typeof value>(value)` | ||
* TypeScript issues a type error since `value is not assignable to never`. | ||
* This means `typeof value` is not identical to `number | string` | ||
* @param actual | ||
*/ | ||
declare function expectType<Expected, Actual>( | ||
actual: IfEquals<Actual, Expected, Actual>, | ||
): void |
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 was
Element
before this change which caused #834 (comment)