11import React , { Component } from 'react'
2- import expect from 'expect'
32import PropTypes from 'prop-types'
43import TestUtils from 'react-dom/test-utils'
54import { ThemeProvider } from '../../src/index'
5+ import { jsdom } from 'jsdom'
66
7- before ( function ( ) {
8- /* eslint-disable no-console */
9- console . error = function ( ) { }
7+ const documentDom = jsdom ( '<!doctype html><html><body></body></html>' )
8+ beforeEach ( ( ) => {
9+ global . document = documentDom
10+ global . window = document . defaultView
11+ global . navigator = global . window . navigator
12+
13+ jest . spyOn ( console , 'error' )
14+ global . console . error . mockImplementation ( ( ) => { } )
1015} )
1116
12- after ( function ( ) {
13- delete console . error
17+ afterEach ( ( ) => {
18+ global . console . error . mockRestore ( )
1419} )
1520
1621describe ( 'ThemeProvider' , ( ) => {
@@ -24,7 +29,7 @@ describe('ThemeProvider', () => {
2429 themr : PropTypes . object . isRequired
2530 }
2631
27- it ( 'enforces a single child' , ( ) => {
32+ test ( 'enforces a single child' , ( ) => {
2833 const theme = { }
2934
3035 // Ignore propTypes warnings
@@ -38,7 +43,7 @@ describe('ThemeProvider', () => {
3843 < div />
3944 </ ThemeProvider >
4045 )
41- ) . toNotThrow ( )
46+ ) . not . toThrow ( )
4247
4348 expect ( ( ) =>
4449 TestUtils . renderIntoDocument (
@@ -57,7 +62,7 @@ describe('ThemeProvider', () => {
5762 }
5863 } )
5964
60- it ( 'should add the theme to the child context' , ( ) => {
65+ test ( 'should add the theme to the child context' , ( ) => {
6166 const theme = { }
6267
6368 TestUtils . renderIntoDocument (
@@ -66,14 +71,13 @@ describe('ThemeProvider', () => {
6671 </ ThemeProvider >
6772 )
6873
69- const spy = expect . spyOn ( console , 'error' )
74+ const spy = jest . spyOn ( console , 'error' )
7075 const tree = TestUtils . renderIntoDocument (
7176 < ThemeProvider theme = { theme } >
7277 < Child />
7378 </ ThemeProvider >
7479 )
75- spy . destroy ( )
76- expect ( spy . calls . length ) . toBe ( 0 )
80+ expect ( spy . mock . calls . length ) . toBe ( 0 )
7781
7882 const child = TestUtils . findRenderedComponentWithType ( tree , Child )
7983 expect ( child . context . themr . theme ) . toBe ( theme )
0 commit comments