11import * as React from 'react'
22import ReactDOM , { unmountComponentAtNode } from 'react-dom'
33import getDisplayName from './getDisplayName'
4+ import { injectStylesBeforeElement } from './utils'
45
56function checkMountModeEnabled ( ) {
67 // @ts -ignore
@@ -11,50 +12,13 @@ function checkMountModeEnabled() {
1112 }
1213}
1314
14- interface MountOptions {
15- alias ?: string
16- ReactDom ?: typeof ReactDOM
17- stylesheets ?: string | string [ ]
18- style ?: string
19- cssFile ?: string
20- }
21-
2215/**
2316 * Inject custom style text or CSS file or 3rd party style resources
2417 */
2518const injectStyles = ( options : MountOptions ) => ( ) => {
2619 const document = cy . state ( 'document' )
27-
2820 const el = document . getElementById ( 'cypress-jsdom' )
29-
30- // insert any custom global styles before the component
31- if ( typeof options . stylesheets === 'string' ) {
32- options . stylesheets = [ options . stylesheets ]
33- }
34- if ( Array . isArray ( options . stylesheets ) ) {
35- // console.log('adding stylesheets')
36- options . stylesheets . forEach ( href => {
37- const link = document . createElement ( 'link' )
38- link . type = 'text/css'
39- link . rel = 'stylesheet'
40- link . href = href
41- document . body . insertBefore ( link , el )
42- } )
43- }
44-
45- if ( options . style ) {
46- const style = document . createElement ( 'style' )
47- style . appendChild ( document . createTextNode ( options . style ) )
48- document . body . insertBefore ( style , el )
49- }
50-
51- if ( options . cssFile ) {
52- return cy . readFile ( options . cssFile ) . then ( css => {
53- const style = document . createElement ( 'style' )
54- style . appendChild ( document . createTextNode ( css ) )
55- document . body . appendChild ( style )
56- } )
57- }
21+ return injectStylesBeforeElement ( options , document , el )
5822}
5923
6024/**
0 commit comments