1
1
import React , { Component } from 'react'
2
- import expect from 'expect'
3
2
import PropTypes from 'prop-types'
4
3
import TestUtils from 'react-dom/test-utils'
5
4
import { ThemeProvider } from '../../src/index'
5
+ import { jsdom } from 'jsdom'
6
6
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 ( ( ) => { } )
10
15
} )
11
16
12
- after ( function ( ) {
13
- delete console . error
17
+ afterEach ( ( ) => {
18
+ global . console . error . mockRestore ( )
14
19
} )
15
20
16
21
describe ( 'ThemeProvider' , ( ) => {
@@ -24,7 +29,7 @@ describe('ThemeProvider', () => {
24
29
themr : PropTypes . object . isRequired
25
30
}
26
31
27
- it ( 'enforces a single child' , ( ) => {
32
+ test ( 'enforces a single child' , ( ) => {
28
33
const theme = { }
29
34
30
35
// Ignore propTypes warnings
@@ -38,7 +43,7 @@ describe('ThemeProvider', () => {
38
43
< div />
39
44
</ ThemeProvider >
40
45
)
41
- ) . toNotThrow ( )
46
+ ) . not . toThrow ( )
42
47
43
48
expect ( ( ) =>
44
49
TestUtils . renderIntoDocument (
@@ -57,7 +62,7 @@ describe('ThemeProvider', () => {
57
62
}
58
63
} )
59
64
60
- it ( 'should add the theme to the child context' , ( ) => {
65
+ test ( 'should add the theme to the child context' , ( ) => {
61
66
const theme = { }
62
67
63
68
TestUtils . renderIntoDocument (
@@ -66,14 +71,13 @@ describe('ThemeProvider', () => {
66
71
</ ThemeProvider >
67
72
)
68
73
69
- const spy = expect . spyOn ( console , 'error' )
74
+ const spy = jest . spyOn ( console , 'error' )
70
75
const tree = TestUtils . renderIntoDocument (
71
76
< ThemeProvider theme = { theme } >
72
77
< Child />
73
78
</ ThemeProvider >
74
79
)
75
- spy . destroy ( )
76
- expect ( spy . calls . length ) . toBe ( 0 )
80
+ expect ( spy . mock . calls . length ) . toBe ( 0 )
77
81
78
82
const child = TestUtils . findRenderedComponentWithType ( tree , Child )
79
83
expect ( child . context . themr . theme ) . toBe ( theme )
0 commit comments