Skip to content

Commit

Permalink
fix(component-testing): ensure to call unmount after each test (#15385)
Browse files Browse the repository at this point in the history
* fix: ensure to call unmount after each test

* fix: do not append beforeEach

* fix: add hook

* chore: move unmount hook into npm/react

* chore: resolve conflicts

* chore: fix tests

Co-authored-by: Barthélémy Ledoux <bart@cypress.io>
  • Loading branch information
lmiller1990 and Barthélémy Ledoux authored Mar 10, 2021
1 parent e84c995 commit 153fc51
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion npm/react/cypress/component/viewport-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('cy.viewport', () => {
minima libero vel? Nam sequi iusto quod fugit vel rerum eligendi beatae voluptatibus numquam.
</p>)

expect(getComputedStyle(window.parent.document.querySelector('iframe').parentElement).transform).to.contain('matrix(1')
expect(getComputedStyle(window.parent.document.querySelector('iframe').parentElement).transform).to.contain('matrix(0.8')
cy.viewport(2000, 200).should(() => {
expect(getComputedStyle(window.parent.document.querySelector('iframe').parentElement).transform).not.to.contain('matrix(1')
})
Expand Down
4 changes: 4 additions & 0 deletions npm/react/src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export const unmount = (options = { log: true }) => {
})
}

beforeEach(() => {
unmount()
})

/**
* Creates new instance of `mount` function with default options
* @function createMount
Expand Down
17 changes: 16 additions & 1 deletion npm/vite-dev-server/cypress/components/react-no-jsx.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@ import { mount } from '@cypress/react'
import { Foo } from './Foo'

describe('React', () => {
it('renders a react component', () => {
it('renders a react component #1', () => {
mount(<Foo />)
cy.get('div').contains('Hello world')
})

it('renders a react component #2', () => {
mount(<Foo />)
cy.get('div').contains('Hello world')
})

it('renders a react component #3', () => {
mount(<Foo />)
cy.get('div').contains('Hello world')
})

it('renders a react component #4', () => {
mount(<Foo />)
cy.get('div').contains('Hello world')
})
Expand Down
2 changes: 1 addition & 1 deletion npm/vite-dev-server/index-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
Cypress.onSpecWindow(window, importsToLoad)
Cypress.action('app:window:before:load', window)

beforeEach(() => {
before(() => {
const root = appendTargetIfNotExists('__cy_root')

root.appendChild(appendTargetIfNotExists('__cy_app'))
Expand Down
4 changes: 1 addition & 3 deletions packages/runner-ct/src/app/RunnerCt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ export const AUT_IFRAME_MARGIN = {

const App: React.FC<AppProps> = observer(
function App (props: AppProps) {
const searchRef = React.createRef<HTMLInputElement>(null)
const searchRef = React.useRef<HTMLInputElement>(null)
const splitPaneRef = React.useRef<{ splitPane: HTMLDivElement }>(null)
const pluginRootContainer = React.useRef<null | HTMLDivElement>(null)

const { state, eventManager, config } = props
const isOpenMode = !config.isTextTerminal

const [isResizing, setIsResizing] = React.useState(false)

const [isSpecsListOpen, setIsSpecsListOpen] = React.useState(isOpenMode)

// const windowSize = useWindowSize()
Expand Down

5 comments on commit 153fc51

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 153fc51 Mar 10, 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/6.7.0/circle-develop-153fc515a53343758393db795879a64494374551/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 153fc51 Mar 10, 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/6.7.0/appveyor-develop-153fc515a53343758393db795879a64494374551/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 153fc51 Mar 10, 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/6.7.0/appveyor-develop-153fc515a53343758393db795879a64494374551/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 153fc51 Mar 10, 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/6.7.0/circle-develop-153fc515a53343758393db795879a64494374551/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 153fc51 Mar 10, 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/6.7.0/circle-develop-153fc515a53343758393db795879a64494374551/cypress.tgz

Please sign in to comment.