diff --git a/src/index.ts b/src/index.ts index 5a2402460..ade034403 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import { DOMWrapper } from './domWrapper' import { VueWrapper } from './vueWrapper' import BaseWrapper from './baseWrapper' import { mount, shallowMount } from './mount' -import { renderToString } from './renderToString' +import { renderToString as _renderToString } from './renderToString' import { MountingOptions } from './types' import { RouterLinkStub } from './components/RouterLinkStub' import { createWrapperError } from './errorWrapper' @@ -10,6 +10,8 @@ import { config } from './config' import { flushPromises } from './utils/flushPromises' import { enableAutoUnmount, disableAutoUnmount } from './utils/autoUnmount' +const isNode = typeof window === 'undefined' +const renderToString = ( isNode ? _renderToString : null) export { mount, shallowMount, diff --git a/tests/index.jsdom.spec.ts b/tests/index.jsdom.spec.ts new file mode 100644 index 000000000..5abb41999 --- /dev/null +++ b/tests/index.jsdom.spec.ts @@ -0,0 +1,10 @@ +// @vitest-environment jsdom +import { describe, expect, it } from 'vitest' + +import * as exports from '../src/index' +describe('index.js exports', () => { + it('in a browser environment renderToString should not be exported', () => { + // data type of null is object + expect(typeof exports.renderToString).toEqual('object'); + }); +}) \ No newline at end of file diff --git a/tests/index.spec.ts b/tests/index.spec.ts new file mode 100644 index 000000000..d2a158659 --- /dev/null +++ b/tests/index.spec.ts @@ -0,0 +1,9 @@ +// @vitest-environment node +import { describe, expect, it } from 'vitest' + +import * as exports from '../src/index' +describe('index.js exports', () => { + it('in a node environment renderToString should be exported', () => { + expect(typeof exports.renderToString).toEqual('function'); + }); +}) \ No newline at end of file