Skip to content

Commit

Permalink
fix: Properly display unmount as a command (#16041)
Browse files Browse the repository at this point in the history
  • Loading branch information
agg23 committed Apr 21, 2021
1 parent 10b89f8 commit 4002e4c
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions npm/react/src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ const _mount = (type: 'mount' | 'rerender', jsx: React.ReactNode, options: Mount
// @ts-ignore FIXME
const componentName = getDisplayName(jsx.type, options.alias)
const displayName = options.alias || componentName

const jsxComponentName = `<${componentName} ... />`

const message = options.alias
? `<${componentName} ... /> as "${options.alias}"`
: `<${componentName} ... />`
? `${jsxComponentName} as "${options.alias}"`
: jsxComponentName

return cy
.then(injectStyles(options))
Expand Down Expand Up @@ -113,7 +116,7 @@ const _mount = (type: 'mount' | 'rerender', jsx: React.ReactNode, options: Mount
return cy.wrap<MountReturn>({
component: userComponent,
rerender: (newComponent) => _mount('rerender', newComponent, options, key),
unmount,
unmount: () => _unmount({ boundComponentMessage: jsxComponentName, log: true }),
}, { log: false })
})
// by waiting, we delaying test execution for the next tick of event loop
Expand Down Expand Up @@ -147,15 +150,28 @@ Cypress.on('run:start', () => {
})
```
*/
export const unmount = (options = { log: true }): globalThis.Cypress.Chainable<JQuery<HTMLElement>> => {
export const unmount = (options = { log: true }): globalThis.Cypress.Chainable<JQuery<HTMLElement>> => _unmount(options)

const _unmount = (options: { boundComponentMessage?: string, log: boolean }) => {
return cy.then(() => {
const selector = `#${ROOT_ID}`

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

if (wasUnmounted && options.log) {
cy.log('Unmounted component at', $el)
Cypress.log({
name: 'unmount',
type: 'parent',
message: [options.boundComponentMessage ?? 'Unmounted component'],
consoleProps: () => {
return {
description: 'Unmounts React component',
parent: $el[0],
home: 'https://github.com/cypress-io/cypress',
}
},
})
}
})
})
Expand Down

4 comments on commit 4002e4c

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 4002e4c Apr 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.2.0/appveyor-develop-4002e4c5fd204a3c6d1feba2b1893f92cec8ef60/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 4002e4c Apr 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.2.0/circle-develop-4002e4c5fd204a3c6d1feba2b1893f92cec8ef60/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 4002e4c Apr 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.2.0/appveyor-develop-4002e4c5fd204a3c6d1feba2b1893f92cec8ef60/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 4002e4c Apr 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.2.0/circle-develop-4002e4c5fd204a3c6d1feba2b1893f92cec8ef60/cypress.tgz

Please sign in to comment.