Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Commit

Permalink
fix: better mount command log, closes #271
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jun 3, 2020
1 parent deb4bc6 commit 779cbfa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
9 changes: 6 additions & 3 deletions cypress/component/advanced/tutorial/square-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ class Square extends React.Component {

render() {
return (
<button className="square" onClick={() => this.setState({ value: 'X' })}>
<button
className="square"
onClick={() => this.setState({ value: this.props.value })}
>
{this.state.value}
</button>
)
}
}

describe('Square', () => {
it('changes value on click', () => {
it.only('changes value on click', () => {
const selector = 'button.square'
mount(<Square />)
mount(<Square value="X" />)
// initially button is blank
cy.get(selector).should('have.text', '')
// but it changes text on click
Expand Down
23 changes: 15 additions & 8 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const mount = (jsx: React.ReactElement, options: MountOptions = {}) => {
if (options.log !== false) {
logInstance = Cypress.log({
name: 'mount',
message: [`ReactDOM.render(<${displayName} ... />)`],
message: [`<${displayName} ... />`],
})
}
})
Expand Down Expand Up @@ -84,15 +84,22 @@ export const mount = (jsx: React.ReactElement, options: MountOptions = {}) => {
key,
}

const CypressTestComponent = reactDomToUse.render(
React.createElement(React.Fragment, props, jsx),
el,
)
const reactComponent = React.createElement(React.Fragment, props, jsx)
const CypressTestComponent = reactDomToUse.render(reactComponent, el)

const logConsoleProps = {
props: jsx.props,
}
if (logInstance) {
const logConsoleProps = {
props: jsx.props,
description: 'Mounts React component',
home: 'https://github.com/bahmutov/cypress-react-unit-test',
}
const componentElement = el.children[0]

if (componentElement) {
// @ts-ignore
logConsoleProps.yielded = reactDomToUse.findDOMNode(componentElement)
}

logInstance.set('consoleProps', () => logConsoleProps)

if (el.children.length) {
Expand Down

0 comments on commit 779cbfa

Please sign in to comment.