Reputation: 186
I have started to write tests for my react components with Mocha. And when I started npm test I got an exception
Invariant Violation: Browser history needs a DOM
I was tried to connect history object to test file:
import React, {Component} from 'react'
import Modal from 'react-modal';
import expect from 'expect'
import TestUtils from 'react-addons-test-utils'
import {AdminPage} from '../../app/DOM/pages/AdminPanel'
const history = require('history');
const historyObj = history.createMemoryHistory();
historyObj.createLocation('/admin');
But I'v got this exception again. How I can solve this problem?
Upvotes: 2
Views: 947
Reputation: 8686
As stated by the error, historyBrowser needs a DOM to work. You can simulate a DOM with a lib like jsdom
to do so. Take a look to this tutorial for testing React components with mocha and jsdom
Upvotes: 4