From a7916c3c7546bcab4d30c17358ecd068eca4084e Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Wed, 1 Apr 2020 15:22:43 -0400 Subject: [PATCH] fix: handle bare div mount (#118) --- cypress/integration/empty-spec.js | 16 ++++++++++++++++ lib/getDisplayName.ts | 2 +- lib/index.ts | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 cypress/integration/empty-spec.js diff --git a/cypress/integration/empty-spec.js b/cypress/integration/empty-spec.js new file mode 100644 index 00000000..45a796fd --- /dev/null +++ b/cypress/integration/empty-spec.js @@ -0,0 +1,16 @@ +/// +/// +import React from 'react' + +/* eslint-env mocha */ +describe('Empty div jsx', () => { + it('works with El', () => { + const El = () =>
foo
+ cy.mount() + }) + + it('works with div', () => { + cy.mount(
I am a div
) + cy.contains('I am a div').should('be.visible') + }) +}) diff --git a/lib/getDisplayName.ts b/lib/getDisplayName.ts index 4aa3c086..e8b6f124 100644 --- a/lib/getDisplayName.ts +++ b/lib/getDisplayName.ts @@ -49,4 +49,4 @@ export default function getDisplayName(type: JSX, fallbackName: string = 'Unknow cachedDisplayNames.set(type, displayName) return displayName -} \ No newline at end of file +} diff --git a/lib/index.ts b/lib/index.ts index 0e8fd25e..e8d61918 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -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;