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'
6
5
7
- before ( function ( ) {
8
- /* eslint-disable no- console */
9
- console . error = function ( ) { }
6
+ beforeEach ( ( ) => {
7
+ jest . spyOn ( console , 'error' )
8
+ global . console . error . mockImplementation ( ( ) => { } )
10
9
} )
11
10
12
- after ( function ( ) {
13
- delete console . error
11
+ afterEach ( ( ) => {
12
+ global . console . error . mockRestore ( )
14
13
} )
15
14
16
15
describe ( 'ThemeProvider' , ( ) => {
@@ -24,7 +23,7 @@ describe('ThemeProvider', () => {
24
23
themr : PropTypes . object . isRequired
25
24
}
26
25
27
- it ( 'enforces a single child' , ( ) => {
26
+ test ( 'enforces a single child' , ( ) => {
28
27
const theme = { }
29
28
30
29
// Ignore propTypes warnings
@@ -38,7 +37,7 @@ describe('ThemeProvider', () => {
38
37
< div />
39
38
</ ThemeProvider >
40
39
)
41
- ) . toNotThrow ( )
40
+ ) . not . toThrow ( )
42
41
43
42
expect ( ( ) =>
44
43
TestUtils . renderIntoDocument (
@@ -57,7 +56,7 @@ describe('ThemeProvider', () => {
57
56
}
58
57
} )
59
58
60
- it ( 'should add the theme to the child context' , ( ) => {
59
+ test ( 'should add the theme to the child context' , ( ) => {
61
60
const theme = { }
62
61
63
62
TestUtils . renderIntoDocument (
@@ -66,14 +65,13 @@ describe('ThemeProvider', () => {
66
65
</ ThemeProvider >
67
66
)
68
67
69
- const spy = expect . spyOn ( console , 'error' )
68
+ const spy = jest . spyOn ( console , 'error' )
70
69
const tree = TestUtils . renderIntoDocument (
71
70
< ThemeProvider theme = { theme } >
72
71
< Child />
73
72
</ ThemeProvider >
74
73
)
75
- spy . destroy ( )
76
- expect ( spy . calls . length ) . toBe ( 0 )
74
+ expect ( spy . mock . calls . length ) . toBe ( 0 )
77
75
78
76
const child = TestUtils . findRenderedComponentWithType ( tree , Child )
79
77
expect ( child . context . themr . theme ) . toBe ( theme )
0 commit comments