From 172dc163f0ec2a5683afe9ce1ec84c82594b4a3a Mon Sep 17 00:00:00 2001 From: MICHAEL JACKSON Date: Fri, 14 Jul 2017 14:13:24 -0700 Subject: [PATCH] Use Jest for testing This commit uses Jest for testing everything instead of our homegrown combination of karma + mocha + expect. We were already using Jest to test react-router-redux and react-router-native, so this commit makes everything more consistent. --- packages/react-router-config/.gitignore | 2 - packages/react-router-config/karma.conf.js | 113 ------------------ .../modules/__tests__/matchRoutes-test.js | 1 - .../modules/__tests__/renderRoutes-test.js | 8 +- packages/react-router-config/package.json | 12 +- packages/react-router-config/tests.webpack.js | 2 - packages/react-router-dom/.gitignore | 2 - packages/react-router-dom/karma.conf.js | 113 ------------------ .../modules/__tests__/BrowserRouter-test.js | 14 +-- .../modules/__tests__/HashRouter-test.js | 14 +-- .../modules/__tests__/Link-test.js | 1 - .../modules/__tests__/NavLink-test.js | 41 ++++--- packages/react-router-dom/package.json | 12 +- packages/react-router-dom/tests.webpack.js | 2 - packages/react-router-native/package.json | 4 +- packages/react-router/.gitignore | 2 - packages/react-router/karma.conf.js | 113 ------------------ .../modules/__tests__/MemoryRouter-test.js | 14 +-- .../modules/__tests__/Route-test.js | 19 ++- .../modules/__tests__/Router-test.js | 5 +- .../modules/__tests__/StaticRouter-test.js | 24 ++-- .../modules/__tests__/Switch-test.js | 9 +- .../modules/__tests__/SwitchMount-test.js | 1 - .../modules/__tests__/integration-test.js | 3 +- .../modules/__tests__/matchPath-test.js | 3 +- .../modules/__tests__/withRouter-test.js | 13 +- packages/react-router/package.json | 12 +- packages/react-router/tests.webpack.js | 2 - 28 files changed, 93 insertions(+), 468 deletions(-) delete mode 100644 packages/react-router-config/karma.conf.js delete mode 100644 packages/react-router-config/tests.webpack.js delete mode 100644 packages/react-router-dom/karma.conf.js delete mode 100644 packages/react-router-dom/tests.webpack.js delete mode 100644 packages/react-router/karma.conf.js delete mode 100644 packages/react-router/tests.webpack.js diff --git a/packages/react-router-config/.gitignore b/packages/react-router-config/.gitignore index b6ddde75b8..e840a2ab14 100644 --- a/packages/react-router-config/.gitignore +++ b/packages/react-router-config/.gitignore @@ -2,6 +2,4 @@ es node_modules umd /*.js -!karma.conf.js -!tests.webpack.js !webpack.config.js diff --git a/packages/react-router-config/karma.conf.js b/packages/react-router-config/karma.conf.js deleted file mode 100644 index 189e56788c..0000000000 --- a/packages/react-router-config/karma.conf.js +++ /dev/null @@ -1,113 +0,0 @@ -const webpack = require('webpack') -const projectName = require('./package').name - -module.exports = (config) => { - const customLaunchers = { - BS_Chrome: { - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'chrome', - browser_version: '47.0' - }, - BS_Firefox: { - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'firefox', - browser_version: '43.0' - }, - BS_Safari: { - base: 'BrowserStack', - os: 'OS X', - os_version: 'El Capitan', - browser: 'safari', - browser_version: '9.0' - }, - BS_MobileSafari8: { - base: 'BrowserStack', - os: 'ios', - os_version: '8.3', - browser: 'iphone', - real_mobile: false - }, - BS_MobileSafari9: { - base: 'BrowserStack', - os: 'ios', - os_version: '9.1', - browser: 'iphone', - real_mobile: false - }, - BS_InternetExplorer10: { - base: 'BrowserStack', - os: 'Windows', - os_version: '8', - browser: 'ie', - browser_version: '10.0' - }, - BS_InternetExplorer11: { - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'ie', - browser_version: '11.0' - } - } - - config.set({ - customLaunchers: customLaunchers, - - browsers: [ 'Chrome' ], - frameworks: [ 'mocha' ], - reporters: [ 'mocha' ], - - files: [ - 'tests.webpack.js' - ], - - preprocessors: { - 'tests.webpack.js': [ 'webpack', 'sourcemap' ] - }, - - webpack: { - devtool: 'inline-source-map', - module: { - loaders: [ - { test: /\.js$/, exclude: /node_modules/, loader: 'babel' } - ] - }, - plugins: [ - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify('test') - }) - ] - }, - - webpackServer: { - noInfo: true - } - }) - - if (process.env.USE_CLOUD) { - config.browsers = Object.keys(customLaunchers) - config.reporters = [ 'dots' ] - config.concurrency = 2 - - config.browserDisconnectTimeout = 10000 - config.browserDisconnectTolerance = 3 - - if (process.env.TRAVIS) { - config.browserStack = { - project: projectName, - build: process.env.TRAVIS_BUILD_NUMBER, - name: process.env.TRAVIS_JOB_NUMBER - } - - config.singleRun = true - } else { - config.browserStack = { - project: projectName - } - } - } -} diff --git a/packages/react-router-config/modules/__tests__/matchRoutes-test.js b/packages/react-router-config/modules/__tests__/matchRoutes-test.js index ab07121564..7ce9b0f7b3 100644 --- a/packages/react-router-config/modules/__tests__/matchRoutes-test.js +++ b/packages/react-router-config/modules/__tests__/matchRoutes-test.js @@ -1,5 +1,4 @@ import matchRoutes from '../matchRoutes' -import expect from 'expect' it('finds matched routes', () => { const routes = [ diff --git a/packages/react-router-config/modules/__tests__/renderRoutes-test.js b/packages/react-router-config/modules/__tests__/renderRoutes-test.js index e3fda9f4c7..1913d9ae7e 100644 --- a/packages/react-router-config/modules/__tests__/renderRoutes-test.js +++ b/packages/react-router-config/modules/__tests__/renderRoutes-test.js @@ -26,7 +26,7 @@ describe('renderRoutes', () => { ) expect(rendered.length).toEqual(1) - expect(rendered[0]).toMatch(routeToMatch) + expect(rendered[0]).toEqual(routeToMatch) }) describe('Switch usage', () => { @@ -45,7 +45,7 @@ describe('renderRoutes', () => { ) expect(rendered.length).toEqual(1) - expect(rendered[0]).toMatch(routeToMatch) + expect(rendered[0]).toEqual(routeToMatch) }) it('renders the first matched route in nested routes', () => { @@ -70,8 +70,8 @@ describe('renderRoutes', () => { ) expect(rendered.length).toEqual(2) - expect(rendered[0]).toMatch(routeToMatch) - expect(rendered[1]).toMatch(childRouteToMatch) + expect(rendered[0]).toEqual(routeToMatch) + expect(rendered[1]).toEqual(childRouteToMatch) }) }) diff --git a/packages/react-router-config/package.json b/packages/react-router-config/package.json index e3f0cc0c34..dd3b031c8a 100644 --- a/packages/react-router-config/package.json +++ b/packages/react-router-config/package.json @@ -22,7 +22,7 @@ "prepublishOnly": "node ./tools/build.js", "clean": "git clean -fdX .", "lint": "eslint modules", - "test": "karma start --single-run" + "test": "jest" }, "peerDependencies": { "react": "^15", @@ -40,16 +40,8 @@ "eslint": "^2.13.1", "eslint-plugin-import": "^1.15.0", "eslint-plugin-react": "^5.2.2", - "expect": "^1.20.1", "gzip-size": "^3.0.0", - "karma": "^0.13.22", - "karma-browserstack-launcher": "^1.0.1", - "karma-chrome-launcher": "^1.0.1", - "karma-mocha": "^1.0.1", - "karma-mocha-reporter": "^2.0.4", - "karma-sourcemap-loader": "^0.3.7", - "karma-webpack": "^1.7.0", - "mocha": "^2.5.3", + "jest": "^20.0.4", "pretty-bytes": "^3.0.1", "react": "^15.4.2", "react-addons-test-utils": "^15.4.2", diff --git a/packages/react-router-config/tests.webpack.js b/packages/react-router-config/tests.webpack.js deleted file mode 100644 index 6518977117..0000000000 --- a/packages/react-router-config/tests.webpack.js +++ /dev/null @@ -1,2 +0,0 @@ -var context = require.context('./modules', true, /-test\.js$/) -context.keys().forEach(context) diff --git a/packages/react-router-dom/.gitignore b/packages/react-router-dom/.gitignore index b6ddde75b8..e840a2ab14 100644 --- a/packages/react-router-dom/.gitignore +++ b/packages/react-router-dom/.gitignore @@ -2,6 +2,4 @@ es node_modules umd /*.js -!karma.conf.js -!tests.webpack.js !webpack.config.js diff --git a/packages/react-router-dom/karma.conf.js b/packages/react-router-dom/karma.conf.js deleted file mode 100644 index 189e56788c..0000000000 --- a/packages/react-router-dom/karma.conf.js +++ /dev/null @@ -1,113 +0,0 @@ -const webpack = require('webpack') -const projectName = require('./package').name - -module.exports = (config) => { - const customLaunchers = { - BS_Chrome: { - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'chrome', - browser_version: '47.0' - }, - BS_Firefox: { - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'firefox', - browser_version: '43.0' - }, - BS_Safari: { - base: 'BrowserStack', - os: 'OS X', - os_version: 'El Capitan', - browser: 'safari', - browser_version: '9.0' - }, - BS_MobileSafari8: { - base: 'BrowserStack', - os: 'ios', - os_version: '8.3', - browser: 'iphone', - real_mobile: false - }, - BS_MobileSafari9: { - base: 'BrowserStack', - os: 'ios', - os_version: '9.1', - browser: 'iphone', - real_mobile: false - }, - BS_InternetExplorer10: { - base: 'BrowserStack', - os: 'Windows', - os_version: '8', - browser: 'ie', - browser_version: '10.0' - }, - BS_InternetExplorer11: { - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'ie', - browser_version: '11.0' - } - } - - config.set({ - customLaunchers: customLaunchers, - - browsers: [ 'Chrome' ], - frameworks: [ 'mocha' ], - reporters: [ 'mocha' ], - - files: [ - 'tests.webpack.js' - ], - - preprocessors: { - 'tests.webpack.js': [ 'webpack', 'sourcemap' ] - }, - - webpack: { - devtool: 'inline-source-map', - module: { - loaders: [ - { test: /\.js$/, exclude: /node_modules/, loader: 'babel' } - ] - }, - plugins: [ - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify('test') - }) - ] - }, - - webpackServer: { - noInfo: true - } - }) - - if (process.env.USE_CLOUD) { - config.browsers = Object.keys(customLaunchers) - config.reporters = [ 'dots' ] - config.concurrency = 2 - - config.browserDisconnectTimeout = 10000 - config.browserDisconnectTolerance = 3 - - if (process.env.TRAVIS) { - config.browserStack = { - project: projectName, - build: process.env.TRAVIS_BUILD_NUMBER, - name: process.env.TRAVIS_JOB_NUMBER - } - - config.singleRun = true - } else { - config.browserStack = { - project: projectName - } - } - } -} diff --git a/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js b/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js index 18023b4f67..0759764f09 100644 --- a/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js +++ b/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import PropTypes from 'prop-types' @@ -24,21 +23,22 @@ describe('A ', () => { ), node) - expect(history).toBeAn('object') + expect(typeof history).toBe('object') }) it('warns when passed a history prop', () => { const history = {} const node = document.createElement('div') - expect.spyOn(console, 'error') + + spyOn(console, 'error') ReactDOM.render(( ), node) - expect(console.error.calls.length).toBe(1) - expect(console.error.calls[0].arguments[0]).toMatch( - / ignores the history prop' + ) }) }) diff --git a/packages/react-router-dom/modules/__tests__/HashRouter-test.js b/packages/react-router-dom/modules/__tests__/HashRouter-test.js index 4a22656d5f..382fdd94d9 100644 --- a/packages/react-router-dom/modules/__tests__/HashRouter-test.js +++ b/packages/react-router-dom/modules/__tests__/HashRouter-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import PropTypes from 'prop-types' @@ -24,21 +23,22 @@ describe('A ', () => { ), node) - expect(history).toBeAn('object') + expect(typeof history).toBe('object') }) it('warns when passed a history prop', () => { const history = {} const node = document.createElement('div') - expect.spyOn(console, 'error') + + spyOn(console, 'error') ReactDOM.render(( ), node) - expect(console.error.calls.length).toBe(1) - expect(console.error.calls[0].arguments[0]).toMatch( - / ignores the history prop' + ) }) }) diff --git a/packages/react-router-dom/modules/__tests__/Link-test.js b/packages/react-router-dom/modules/__tests__/Link-test.js index 1770bf04b8..c2f1b37d69 100644 --- a/packages/react-router-dom/modules/__tests__/Link-test.js +++ b/packages/react-router-dom/modules/__tests__/Link-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import MemoryRouter from 'react-router/MemoryRouter' diff --git a/packages/react-router-dom/modules/__tests__/NavLink-test.js b/packages/react-router-dom/modules/__tests__/NavLink-test.js index 55d32cbdb5..6b8f2439e9 100644 --- a/packages/react-router-dom/modules/__tests__/NavLink-test.js +++ b/packages/react-router-dom/modules/__tests__/NavLink-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import MemoryRouter from 'react-router/MemoryRouter' @@ -29,7 +28,8 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active').toEqual('selected') + expect(a.className).not.toContain('active') + expect(a.className).toEqual('selected') }) it('applies its activeStyle', () => { @@ -60,7 +60,7 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active') + expect(a.className).not.toContain('active') }) it('does not apply its passed activeClassName', () => { @@ -70,7 +70,8 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active').toNotContain('selected') + expect(a.className).not.toContain('active') + expect(a.className).not.toContain('selected') }) it('does not apply its activeStyle', () => { @@ -122,7 +123,8 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active').toEqual('selected') + expect(a.className).not.toContain('active') + expect(a.className).toEqual('selected') }) it('does not apply active default props when isActive returns false', () => { @@ -137,7 +139,7 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active') + expect(a.className).not.toContain('active') }) it('does not apply active passed props when isActive returns false', () => { @@ -153,7 +155,8 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active').toNotContain('selected') + expect(a.className).not.toContain('active') + expect(a.className).not.toContain('selected') }) }) @@ -185,7 +188,8 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active').toEqual('selected') + expect(a.className).not.toContain('active') + expect(a.className).toEqual('selected') }) it('does not set active default value for partial matches', () => { @@ -195,7 +199,7 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active') + expect(a.className).not.toContain('active') }) it('does not set active passed value for partial matches', () => { @@ -205,7 +209,8 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active').toNotContain('selected') + expect(a.className).not.toContain('active') + expect(a.className).not.toContain('selected') }) }) @@ -228,7 +233,7 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active') + expect(a.className).not.toContain('active') }) it('does not set active passed value when location.pathname has no trailing slash', () => { @@ -238,7 +243,8 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active').toNotContain('selected') + expect(a.className).not.toContain('active') + expect(a.className).not.toContain('selected') }) it('sets active default value when pathname has trailing slash', () => { @@ -258,7 +264,8 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active').toEqual('selected') + expect(a.className).not.toContain('active') + expect(a.className).toEqual('selected') }) }) @@ -270,9 +277,10 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active').toContain('selected') + expect(a.className).not.toContain('active') + expect(a.className).toContain('selected') }) - + it('is not overwritten by the current location', () => { ReactDOM.render(( @@ -280,7 +288,8 @@ describe('NavLink', () => { ), node) const a = node.getElementsByTagName('a')[0] - expect(a.className).toNotContain('active').toNotContain('selected') + expect(a.className).not.toContain('active') + expect(a.className).not.toContain('selected') }) }) }) diff --git a/packages/react-router-dom/package.json b/packages/react-router-dom/package.json index a975da3e6e..a6f221bef6 100644 --- a/packages/react-router-dom/package.json +++ b/packages/react-router-dom/package.json @@ -34,7 +34,7 @@ "prepublishOnly": "node ./tools/build.js", "clean": "git clean -fdX .", "lint": "eslint modules", - "test": "karma start --single-run" + "test": "jest" }, "peerDependencies": { "react": "^15" @@ -58,16 +58,8 @@ "eslint": "^2.13.1", "eslint-plugin-import": "^1.15.0", "eslint-plugin-react": "^5.2.2", - "expect": "^1.20.1", "gzip-size": "^3.0.0", - "karma": "^0.13.22", - "karma-browserstack-launcher": "^1.0.1", - "karma-chrome-launcher": "^1.0.1", - "karma-mocha": "^1.0.1", - "karma-mocha-reporter": "^2.0.4", - "karma-sourcemap-loader": "^0.3.7", - "karma-webpack": "^1.7.0", - "mocha": "^2.5.3", + "jest": "^20.0.4", "pretty-bytes": "^3.0.1", "react": "^15.4.2", "react-addons-test-utils": "^15.4.2", diff --git a/packages/react-router-dom/tests.webpack.js b/packages/react-router-dom/tests.webpack.js deleted file mode 100644 index 6518977117..0000000000 --- a/packages/react-router-dom/tests.webpack.js +++ /dev/null @@ -1,2 +0,0 @@ -var context = require.context('./modules', true, /-test\.js$/) -context.keys().forEach(context) diff --git a/packages/react-router-native/package.json b/packages/react-router-native/package.json index 5c3d90364c..4870a87287 100644 --- a/packages/react-router-native/package.json +++ b/packages/react-router-native/package.json @@ -35,8 +35,8 @@ "babel-jest": "18.0.0", "babel-preset-react-native": "1.9.1", "jest": "18.1.0", - "react": "15.4.1", - "react-native": "0.42.0", + "react": "^16.0.0-alpha.6", + "react-native": "0.44.0", "react-test-renderer": "15.5.4" }, "jest": { diff --git a/packages/react-router/.gitignore b/packages/react-router/.gitignore index b6ddde75b8..e840a2ab14 100644 --- a/packages/react-router/.gitignore +++ b/packages/react-router/.gitignore @@ -2,6 +2,4 @@ es node_modules umd /*.js -!karma.conf.js -!tests.webpack.js !webpack.config.js diff --git a/packages/react-router/karma.conf.js b/packages/react-router/karma.conf.js deleted file mode 100644 index 189e56788c..0000000000 --- a/packages/react-router/karma.conf.js +++ /dev/null @@ -1,113 +0,0 @@ -const webpack = require('webpack') -const projectName = require('./package').name - -module.exports = (config) => { - const customLaunchers = { - BS_Chrome: { - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'chrome', - browser_version: '47.0' - }, - BS_Firefox: { - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'firefox', - browser_version: '43.0' - }, - BS_Safari: { - base: 'BrowserStack', - os: 'OS X', - os_version: 'El Capitan', - browser: 'safari', - browser_version: '9.0' - }, - BS_MobileSafari8: { - base: 'BrowserStack', - os: 'ios', - os_version: '8.3', - browser: 'iphone', - real_mobile: false - }, - BS_MobileSafari9: { - base: 'BrowserStack', - os: 'ios', - os_version: '9.1', - browser: 'iphone', - real_mobile: false - }, - BS_InternetExplorer10: { - base: 'BrowserStack', - os: 'Windows', - os_version: '8', - browser: 'ie', - browser_version: '10.0' - }, - BS_InternetExplorer11: { - base: 'BrowserStack', - os: 'Windows', - os_version: '10', - browser: 'ie', - browser_version: '11.0' - } - } - - config.set({ - customLaunchers: customLaunchers, - - browsers: [ 'Chrome' ], - frameworks: [ 'mocha' ], - reporters: [ 'mocha' ], - - files: [ - 'tests.webpack.js' - ], - - preprocessors: { - 'tests.webpack.js': [ 'webpack', 'sourcemap' ] - }, - - webpack: { - devtool: 'inline-source-map', - module: { - loaders: [ - { test: /\.js$/, exclude: /node_modules/, loader: 'babel' } - ] - }, - plugins: [ - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify('test') - }) - ] - }, - - webpackServer: { - noInfo: true - } - }) - - if (process.env.USE_CLOUD) { - config.browsers = Object.keys(customLaunchers) - config.reporters = [ 'dots' ] - config.concurrency = 2 - - config.browserDisconnectTimeout = 10000 - config.browserDisconnectTolerance = 3 - - if (process.env.TRAVIS) { - config.browserStack = { - project: projectName, - build: process.env.TRAVIS_BUILD_NUMBER, - name: process.env.TRAVIS_JOB_NUMBER - } - - config.singleRun = true - } else { - config.browserStack = { - project: projectName - } - } - } -} diff --git a/packages/react-router/modules/__tests__/MemoryRouter-test.js b/packages/react-router/modules/__tests__/MemoryRouter-test.js index 31f0e78a89..af77ea67c6 100644 --- a/packages/react-router/modules/__tests__/MemoryRouter-test.js +++ b/packages/react-router/modules/__tests__/MemoryRouter-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import PropTypes from 'prop-types' @@ -24,21 +23,22 @@ describe('A ', () => { ), node) - expect(history).toBeAn('object') + expect(typeof history).toBe('object') }) it('warns when passed a history prop', () => { const history = {} const node = document.createElement('div') - expect.spyOn(console, 'error') + + spyOn(console, 'error') ReactDOM.render(( ), node) - expect(console.error.calls.length).toBe(1) - expect(console.error.calls[0].arguments[0]).toMatch( - / ignores the history prop' + ) }) }) diff --git a/packages/react-router/modules/__tests__/Route-test.js b/packages/react-router/modules/__tests__/Route-test.js index 3a76650aae..218bc876df 100644 --- a/packages/react-router/modules/__tests__/Route-test.js +++ b/packages/react-router/modules/__tests__/Route-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import createMemoryHistory from 'history/createMemoryHistory' @@ -34,7 +33,7 @@ describe('A ', () => { ), node) - expect(node.innerHTML).toNotContain(TEXT) + expect(node.innerHTML).not.toContain(TEXT) }) it('can use a `location` prop instead of `context.router.route.location`', () => { @@ -156,8 +155,8 @@ describe('', () => { ), node) expect(actual.history).toBe(history) - expect(actual.match).toBeAn('object') - expect(actual.location).toBeAn('object') + expect(typeof actual.match).toBe('object') + expect(typeof actual.location).toBe('object') }) }) @@ -193,8 +192,8 @@ describe('', () => { ), node) expect(actual.history).toBe(history) - expect(actual.match).toBeAn('object') - expect(actual.location).toBeAn('object') + expect(typeof actual.match).toBe('object') + expect(typeof actual.location).toBe('object') }) }) @@ -242,8 +241,8 @@ describe('', () => { ), node) expect(actual.history).toBe(history) - expect(actual.match).toBeAn('object') - expect(actual.location).toBeAn('object') + expect(typeof actual.match).toBe('object') + expect(typeof actual.location).toBe('object') }) }) @@ -292,7 +291,7 @@ describe('A ', () => { ), node) - expect(node.innerHTML).toNotContain(TEXT) + expect(node.innerHTML).not.toContain(TEXT) }) it('does not render when the URL does not have a trailing slash', () => { @@ -307,7 +306,7 @@ describe('A ', () => { ), node) - expect(node.innerHTML).toNotContain(TEXT) + expect(node.innerHTML).not.toContain(TEXT) }) }) diff --git a/packages/react-router/modules/__tests__/Router-test.js b/packages/react-router/modules/__tests__/Router-test.js index b0ad8e9307..0f3fdb29ea 100644 --- a/packages/react-router/modules/__tests__/Router-test.js +++ b/packages/react-router/modules/__tests__/Router-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import PropTypes from 'prop-types' @@ -35,7 +34,7 @@ describe('A ', () => { , node ) - }).toNotThrow() + }).not.toThrow() }) }) @@ -46,7 +45,7 @@ describe('A ', () => { , node ) - }).toNotThrow() + }).not.toThrow() }) }) diff --git a/packages/react-router/modules/__tests__/StaticRouter-test.js b/packages/react-router/modules/__tests__/StaticRouter-test.js index b5e7b02a16..288699258a 100644 --- a/packages/react-router/modules/__tests__/StaticRouter-test.js +++ b/packages/react-router/modules/__tests__/StaticRouter-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import ReactDOMServer from 'react-dom/server' @@ -11,7 +10,7 @@ import Prompt from '../Prompt' describe('A ', () => { it('provides context.router.staticContext in props.staticContext', () => { const ContextChecker = (props, reactContext) => { - expect(reactContext.router).toBeAn('object') + expect(typeof reactContext.router).toBe('object') expect(reactContext.router.staticContext).toBe(props.staticContext) return null } @@ -31,7 +30,7 @@ describe('A ', () => { it('context.router.staticContext persists inside of a ', () => { const ContextChecker = (props, reactContext) => { - expect(reactContext.router).toBeAn('object') + expect(typeof reactContext.router).toBe('object') expect(reactContext.router.staticContext).toBe(context) return null } @@ -51,7 +50,7 @@ describe('A ', () => { it('provides context.router.history', () => { const ContextChecker = (props, reactContext) => { - expect(reactContext.router.history).toBeAn('object') + expect(typeof reactContext.router.history).toBe('object') return null } @@ -72,16 +71,17 @@ describe('A ', () => { const context = {} const history = {} const node = document.createElement('div') - expect.spyOn(console, 'error') + + spyOn(console, 'error') ReactDOM.render(( ), node) - expect(console.error.calls.length).toBe(1) - expect(console.error.calls[0].arguments[0]).toMatch( - / ignores the history prop' + ) }) it('reports PUSH actions on the context object', () => { @@ -128,7 +128,7 @@ describe('A ', () => { it('knows how to parse raw URLs', () => { const LocationChecker = (props) => { - expect(props.location).toMatch({ + expect(props.location).toMatchObject({ pathname: '/the/path', search: '?the=query', hash: '#the-hash' @@ -148,7 +148,7 @@ describe('A ', () => { describe('with a basename', () => { it('strips the basename from location pathnames', () => { const LocationChecker = (props) => { - expect(props.location).toMatch({ + expect(props.location).toMatchObject({ pathname: '/path' }) return null @@ -224,7 +224,7 @@ describe('A ', () => { ), node) - }).toNotThrow() + }).not.toThrow() }) }) diff --git a/packages/react-router/modules/__tests__/Switch-test.js b/packages/react-router/modules/__tests__/Switch-test.js index c87f8b51b3..2d768e16a4 100644 --- a/packages/react-router/modules/__tests__/Switch-test.js +++ b/packages/react-router/modules/__tests__/Switch-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import MemoryRouter from '../MemoryRouter' @@ -67,7 +66,7 @@ describe('A ', () => { ), node) - expect(node.innerHTML).toNotMatch(/two/) + expect(node.innerHTML).not.toMatch(/two/) }) it('renders pathless Routes', () => { @@ -82,7 +81,7 @@ describe('A ', () => { ), node) - expect(node.innerHTML).toNotContain('one') + expect(node.innerHTML).not.toContain('one') expect(node.innerHTML).toContain('two') }) @@ -99,7 +98,7 @@ describe('A ', () => { ), node) - expect(node.innerHTML).toNotContain('cup') + expect(node.innerHTML).not.toContain('cup') expect(node.innerHTML).toContain('bub') }) @@ -116,7 +115,7 @@ describe('A ', () => { ), node) - expect(node.innerHTML).toNotContain('bub') + expect(node.innerHTML).not.toContain('bub') expect(node.innerHTML).toContain('cup') }) diff --git a/packages/react-router/modules/__tests__/SwitchMount-test.js b/packages/react-router/modules/__tests__/SwitchMount-test.js index 4cc75d999f..e02589a587 100644 --- a/packages/react-router/modules/__tests__/SwitchMount-test.js +++ b/packages/react-router/modules/__tests__/SwitchMount-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import createHistory from 'history/createMemoryHistory' diff --git a/packages/react-router/modules/__tests__/integration-test.js b/packages/react-router/modules/__tests__/integration-test.js index 693d8d3554..c8a03b3fa3 100644 --- a/packages/react-router/modules/__tests__/integration-test.js +++ b/packages/react-router/modules/__tests__/integration-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import MemoryRouter from '../MemoryRouter' @@ -42,7 +41,7 @@ describe('Integration Tests', () => { ), node) expect(node.innerHTML).toContain(TEXT1) - expect(node.innerHTML).toNotContain(TEXT2) + expect(node.innerHTML).not.toContain(TEXT2) }) it('renders multiple matching routes', () => { diff --git a/packages/react-router/modules/__tests__/matchPath-test.js b/packages/react-router/modules/__tests__/matchPath-test.js index 26a2cfcd1c..765b4001cf 100644 --- a/packages/react-router/modules/__tests__/matchPath-test.js +++ b/packages/react-router/modules/__tests__/matchPath-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import matchPath from '../matchPath' describe('matchPath', () => { @@ -37,7 +36,7 @@ describe('matchPath', () => { describe('with no path', () => { it('matches the root URL', () => { const match = matchPath('/test-location/7', {}) - expect(match).toMatch({ + expect(match).toMatchObject({ url: '/', path: '/', params: {}, diff --git a/packages/react-router/modules/__tests__/withRouter-test.js b/packages/react-router/modules/__tests__/withRouter-test.js index 7bc84efa20..e9d53e76b8 100644 --- a/packages/react-router/modules/__tests__/withRouter-test.js +++ b/packages/react-router/modules/__tests__/withRouter-test.js @@ -1,4 +1,3 @@ -import expect from 'expect' import React from 'react' import ReactDOM from 'react-dom' import MemoryRouter from '../MemoryRouter' @@ -15,9 +14,9 @@ describe('withRouter', () => { it('provides { match, location, history } props', () => { const PropsChecker = withRouter(props => { - expect(props.match).toBeAn('object') - expect(props.location).toBeAn('object') - expect(props.history).toBeAn('object') + expect(typeof props.match).toBe('object') + expect(typeof props.location).toBe('object') + expect(typeof props.history).toBe('object') return null }) @@ -50,7 +49,7 @@ describe('withRouter', () => { describe('inside a ', () => { it('provides the staticContext prop', () => { const PropsChecker = withRouter(props => { - expect(props.staticContext).toBeAn('object') + expect(typeof props.staticContext).toBe('object') expect(props.staticContext).toBe(context) return null }) @@ -88,7 +87,7 @@ describe('withRouter', () => { ), node) - expect(ref).toBeA(WrappedComponent) + expect(ref instanceof WrappedComponent).toBe(true) }) it('hoists non-react statics from the wrapped component', () => { @@ -106,7 +105,7 @@ describe('withRouter', () => { const decorated = withRouter(Component) expect(decorated.hello).toBe('world') - expect(decorated.foo).toBeA('function') + expect(typeof decorated.foo).toBe('function') expect(decorated.foo()).toBe('bar') }) }) diff --git a/packages/react-router/package.json b/packages/react-router/package.json index 8a577d3141..26d8b2cec5 100644 --- a/packages/react-router/package.json +++ b/packages/react-router/package.json @@ -30,7 +30,7 @@ "prepublishOnly": "node ./tools/build.js", "clean": "git clean -fdX .", "lint": "eslint modules", - "test": "karma start --single-run" + "test": "jest" }, "peerDependencies": { "react": "^15" @@ -56,16 +56,8 @@ "eslint": "^3.19.0", "eslint-plugin-import": "^2.2.0", "eslint-plugin-react": "^6.10.3", - "expect": "^1.20.1", "gzip-size": "^3.0.0", - "karma": "^0.13.22", - "karma-browserstack-launcher": "^1.0.1", - "karma-chrome-launcher": "^1.0.1", - "karma-mocha": "^1.0.1", - "karma-mocha-reporter": "^2.0.4", - "karma-sourcemap-loader": "^0.3.7", - "karma-webpack": "^1.7.0", - "mocha": "^2.5.3", + "jest": "^20.0.4", "pretty-bytes": "^3.0.1", "react": "^15.4.2", "react-addons-test-utils": "^15.4.2", diff --git a/packages/react-router/tests.webpack.js b/packages/react-router/tests.webpack.js deleted file mode 100644 index 6518977117..0000000000 --- a/packages/react-router/tests.webpack.js +++ /dev/null @@ -1,2 +0,0 @@ -var context = require.context('./modules', true, /-test\.js$/) -context.keys().forEach(context)