Skip to content

Commit 4002e4c

Browse files
authored
fix: Properly display unmount as a command (#16041)
1 parent 10b89f8 commit 4002e4c

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

npm/react/src/mount.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ const _mount = (type: 'mount' | 'rerender', jsx: React.ReactNode, options: Mount
4848
// @ts-ignore FIXME
4949
const componentName = getDisplayName(jsx.type, options.alias)
5050
const displayName = options.alias || componentName
51+
52+
const jsxComponentName = `<${componentName} ... />`
53+
5154
const message = options.alias
52-
? `<${componentName} ... /> as "${options.alias}"`
53-
: `<${componentName} ... />`
55+
? `${jsxComponentName} as "${options.alias}"`
56+
: jsxComponentName
5457

5558
return cy
5659
.then(injectStyles(options))
@@ -113,7 +116,7 @@ const _mount = (type: 'mount' | 'rerender', jsx: React.ReactNode, options: Mount
113116
return cy.wrap<MountReturn>({
114117
component: userComponent,
115118
rerender: (newComponent) => _mount('rerender', newComponent, options, key),
116-
unmount,
119+
unmount: () => _unmount({ boundComponentMessage: jsxComponentName, log: true }),
117120
}, { log: false })
118121
})
119122
// by waiting, we delaying test execution for the next tick of event loop
@@ -147,15 +150,28 @@ Cypress.on('run:start', () => {
147150
})
148151
```
149152
*/
150-
export const unmount = (options = { log: true }): globalThis.Cypress.Chainable<JQuery<HTMLElement>> => {
153+
export const unmount = (options = { log: true }): globalThis.Cypress.Chainable<JQuery<HTMLElement>> => _unmount(options)
154+
155+
const _unmount = (options: { boundComponentMessage?: string, log: boolean }) => {
151156
return cy.then(() => {
152157
const selector = `#${ROOT_ID}`
153158

154159
return cy.get(selector, { log: false }).then(($el) => {
155160
const wasUnmounted = ReactDOM.unmountComponentAtNode($el[0])
156161

157162
if (wasUnmounted && options.log) {
158-
cy.log('Unmounted component at', $el)
163+
Cypress.log({
164+
name: 'unmount',
165+
type: 'parent',
166+
message: [options.boundComponentMessage ?? 'Unmounted component'],
167+
consoleProps: () => {
168+
return {
169+
description: 'Unmounts React component',
170+
parent: $el[0],
171+
home: 'https://github.com/cypress-io/cypress',
172+
}
173+
},
174+
})
159175
}
160176
})
161177
})

0 commit comments

Comments
 (0)