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

Commit a16c802

Browse files
committed
slightly better console log
1 parent ffcc1ee commit a16c802

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

cypress/component/advanced/react-book-example/src/components/ProductsList.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ it('renders without crashing', () => {
1010
.withArgs('http://myapi.com/products')
1111
.resolves({
1212
json: cy.stub().resolves({
13-
products: [{ id: 1, name: 'nocked data' }],
13+
products: [{ id: 1, name: 'Mocked data' }],
1414
}),
1515
})
1616
mount(<ProductsList />)
17-
cy.contains('nocked data').should('be.visible')
17+
cy.contains('Mocked data').should('be.visible')
1818
})

lib/index.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,14 @@ export const mount = (jsx: React.ReactElement, options: MountOptions = {}) => {
4646
// Get the display name property via the component constructor
4747
// @ts-ignore FIXME
4848
const displayname = getDisplayName(jsx.type, options.alias)
49+
let logInstance: Cypress.Log
4950

5051
return cy
5152
.then(() => {
5253
if (options.log !== false) {
53-
Cypress.log({
54+
logInstance = Cypress.log({
5455
name: 'mount',
5556
message: [`ReactDOM.render(<${displayname} ... />)`],
56-
consoleProps() {
57-
return {
58-
props: jsx.props,
59-
}
60-
},
6157
})
6258
}
6359
})
@@ -80,9 +76,29 @@ export const mount = (jsx: React.ReactElement, options: MountOptions = {}) => {
8076
el,
8177
)
8278

83-
cy.wrap(CypressTestComponent, { log: false }).as(
84-
options.alias || displayname,
85-
)
79+
const logConsoleProps = {
80+
props: jsx.props,
81+
}
82+
if (logInstance) {
83+
logInstance.set('consoleProps', () => logConsoleProps)
84+
85+
if (el.children.length) {
86+
console.log('element', el.children.item(0))
87+
logInstance.set('$el', el.children.item(0))
88+
}
89+
}
90+
91+
return cy
92+
.wrap(CypressTestComponent, { log: false })
93+
.as(options.alias || displayname)
94+
.then(() => {
95+
if (logInstance) {
96+
logInstance.snapshot('mounted')
97+
logInstance.end()
98+
}
99+
100+
return undefined
101+
})
86102
})
87103
}
88104

0 commit comments

Comments
 (0)