Skip to content

Commit e4e963c

Browse files
author
Markus Günther
committed
TASK: Adjust test jest syntax
1 parent ecc6874 commit e4e963c

File tree

4 files changed

+61
-56
lines changed

4 files changed

+61
-56
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"lint": "eslint src test",
6060
"lint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
6161
"prepublish": "rimraf lib && npm run build",
62-
"test": "mocha --compilers js:babel-core/register --recursive --reporter spec --require ./test/setup.js",
62+
"test": "jest",
6363
"test:watch": "npm test -- --watch"
6464
},
6565
"license": "MIT",
@@ -77,5 +77,9 @@
7777
"mocha",
7878
"jsdom"
7979
]
80+
},
81+
"jest": {
82+
"verbose": true,
83+
"testURL": "http://localhost/"
8084
}
8185
}

test/components/ThemeProvider.spec.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import React, { Component } from 'react'
2-
import expect from 'expect'
32
import PropTypes from 'prop-types'
43
import TestUtils from 'react-dom/test-utils'
54
import { ThemeProvider } from '../../src/index'
65

7-
before(function() {
8-
/* eslint-disable no-console */
9-
console.error = function() {}
6+
beforeEach(() => {
7+
jest.spyOn(console, 'error')
8+
global.console.error.mockImplementation(() => {})
109
})
1110

12-
after(function() {
13-
delete console.error
11+
afterEach(() => {
12+
global.console.error.mockRestore()
1413
})
1514

1615
describe('ThemeProvider', () => {
@@ -24,7 +23,7 @@ describe('ThemeProvider', () => {
2423
themr: PropTypes.object.isRequired
2524
}
2625

27-
it('enforces a single child', () => {
26+
test('enforces a single child', () => {
2827
const theme = {}
2928

3029
// Ignore propTypes warnings
@@ -38,7 +37,7 @@ describe('ThemeProvider', () => {
3837
<div />
3938
</ThemeProvider>
4039
)
41-
).toNotThrow()
40+
).not.toThrow()
4241

4342
expect(() =>
4443
TestUtils.renderIntoDocument(
@@ -57,7 +56,7 @@ describe('ThemeProvider', () => {
5756
}
5857
})
5958

60-
it('should add the theme to the child context', () => {
59+
test('should add the theme to the child context', () => {
6160
const theme = {}
6261

6362
TestUtils.renderIntoDocument(
@@ -66,14 +65,13 @@ describe('ThemeProvider', () => {
6665
</ThemeProvider>
6766
)
6867

69-
const spy = expect.spyOn(console, 'error')
68+
const spy = jest.spyOn(console, 'error')
7069
const tree = TestUtils.renderIntoDocument(
7170
<ThemeProvider theme={theme}>
7271
<Child />
7372
</ThemeProvider>
7473
)
75-
spy.destroy()
76-
expect(spy.calls.length).toBe(0)
74+
expect(spy.mock.calls.length).toBe(0)
7775

7876
const child = TestUtils.findRenderedComponentWithType(tree, Child)
7977
expect(child.context.themr.theme).toBe(theme)

0 commit comments

Comments
 (0)