Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Error with enzyme mount function #9

Open
rolele opened this issue Jul 15, 2017 · 1 comment
Open

Error with enzyme mount function #9

rolele opened this issue Jul 15, 2017 · 1 comment

Comments

@rolele
Copy link

rolele commented Jul 15, 2017

jest-environment-node-debug-fixed
is generating this error on all tests:

TypeError: ModuleMocker is not a constructor

jest-environment-node-debug work a little better in my case but fail on managing global vars.

simple tests such as

import React from 'react'
import { mount, shallow } from 'enzyme'
import GenericTemplate from '.'

const wrap = (props = {}) => shallow(
  <GenericTemplate {...props}>test</GenericTemplate>
)

it('mounts', () => {
  mount(<GenericTemplate>test</GenericTemplate>)
})

it('renders children when passed in', () => {
  const wrapper = wrap()
  expect(wrapper.contains('test')).toBe(true)
})

Will fail with the output

It looks like you called `mount()` without a global document being loaded.

Also trying to mock window like that:

window.gapi = {
  load: () => {},
  auth2: {
    init: () => auth2,
    getAuthInstance: () => auth2,
  },
}

will fail with the output

ReferenceError: window is not defined

Without using the debugger and --env jest-environment-node-debug all my tests passes without errors.

@NikhilVerma
Copy link
Owner

This debugger was merged with jest-environment-node-debug but do you mind trying this out if you use jsdom environment in your code? https://www.npmjs.com/package/jest-environment-jsdom-debug

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants