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

Commit

Permalink
fix: handle bare div mount (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov authored Apr 1, 2020
1 parent 8a23f96 commit a7916c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
16 changes: 16 additions & 0 deletions cypress/integration/empty-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference types="cypress" />
/// <reference types="../../lib" />
import React from 'react'

/* eslint-env mocha */
describe('Empty div jsx', () => {
it('works with El', () => {
const El = () => <div>foo</div>
cy.mount(<El></El>)
})

it('works with div', () => {
cy.mount(<div>I am a div</div>)
cy.contains('I am a div').should('be.visible')
})
})
2 changes: 1 addition & 1 deletion lib/getDisplayName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ export default function getDisplayName(type: JSX, fallbackName: string = 'Unknow
cachedDisplayNames.set(type, displayName)

return displayName
}
}
3 changes: 2 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ Cypress.Commands.add('copyComponentStyles', component => {
**/
export const mount = (jsx: JSXElement, alias?: string) => {
// Get the display name property via the component constructor
const displayname = getDisplayName(jsx.type, alias)
const jsxType = typeof jsx.type === 'string' ? jsx as unknown as JSX : jsx.type
const displayname = getDisplayName(jsxType, alias)

let cmd: Cypress.Log;

Expand Down

0 comments on commit a7916c3

Please sign in to comment.