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

Commit a7916c3

Browse files
authored
fix: handle bare div mount (#118)
1 parent 8a23f96 commit a7916c3

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

cypress/integration/empty-spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference types="cypress" />
2+
/// <reference types="../../lib" />
3+
import React from 'react'
4+
5+
/* eslint-env mocha */
6+
describe('Empty div jsx', () => {
7+
it('works with El', () => {
8+
const El = () => <div>foo</div>
9+
cy.mount(<El></El>)
10+
})
11+
12+
it('works with div', () => {
13+
cy.mount(<div>I am a div</div>)
14+
cy.contains('I am a div').should('be.visible')
15+
})
16+
})

lib/getDisplayName.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ export default function getDisplayName(type: JSX, fallbackName: string = 'Unknow
4949
cachedDisplayNames.set(type, displayName)
5050

5151
return displayName
52-
}
52+
}

lib/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ Cypress.Commands.add('copyComponentStyles', component => {
108108
**/
109109
export const mount = (jsx: JSXElement, alias?: string) => {
110110
// Get the display name property via the component constructor
111-
const displayname = getDisplayName(jsx.type, alias)
111+
const jsxType = typeof jsx.type === 'string' ? jsx as unknown as JSX : jsx.type
112+
const displayname = getDisplayName(jsxType, alias)
112113

113114
let cmd: Cypress.Log;
114115

0 commit comments

Comments
 (0)