Skip to content

Commit a6a8b61

Browse files
committed
Rewrite tests
1 parent 3e80ff3 commit a6a8b61

File tree

13 files changed

+128
-138
lines changed

13 files changed

+128
-138
lines changed

.babelrc

Lines changed: 0 additions & 29 deletions
This file was deleted.

test/actions.spec.js renamed to __tests__/actions.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import test from 'ava'
2-
31
import { UPDATE, updateIntl } from '..'
42

5-
test('updateIntl should create action', t => {
3+
test('updateIntl should create action', () => {
64
const locale = 'it'
75
const messages = {}
8-
t.deepEqual(updateIntl({ locale, messages }), {
6+
7+
expect(updateIntl({ locale, messages })).toEqual({
98
type: UPDATE,
109
payload: { locale, messages, formats: undefined }
1110
})
1211
})
1312

14-
test('updateIntl should include formats', t => {
13+
test('updateIntl should include formats', () => {
1514
const locale = 'it'
1615
const formats = {}
17-
t.deepEqual(updateIntl({ locale, formats }), {
16+
17+
expect(updateIntl({ locale, formats })).toEqual({
1818
type: UPDATE,
1919
payload: { locale, formats, messages: undefined }
2020
})
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import test from 'ava'
2-
3-
import { createStore, combineReducers } from 'redux'
1+
import Enzyme, { shallow } from 'enzyme'
2+
import Adapter from 'enzyme-adapter-react-16'
3+
import React from 'react'
44
import { FormattedNumber } from 'react-intl'
55
import { Provider } from 'react-redux'
6-
import { shallow } from 'enzyme'
7-
import React from 'react'
8-
6+
import { combineReducers, createStore } from 'redux'
97
import { IntlProvider, intlReducer } from '../..'
108

11-
test('IntlProvider should render default en locale', t => {
9+
Enzyme.configure({ adapter: new Adapter() })
10+
11+
test('IntlProvider should render default en locale', () => {
1212
const reducer = combineReducers({
1313
intl: intlReducer
1414
})
@@ -21,5 +21,6 @@ test('IntlProvider should render default en locale', t => {
2121
</Provider>
2222
)
2323
const app = shallow(<App />)
24-
t.is(app.html(), '<span>1,000</span>')
24+
25+
expect(app.html()).toBe('<span>1,000</span>')
2526
})

__tests__/components/Provider.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Enzyme, { shallow } from 'enzyme'
2+
import Adapter from 'enzyme-adapter-react-16'
3+
import React from 'react'
4+
import { FormattedNumber } from 'react-intl'
5+
import { combineReducers, createStore } from 'redux'
6+
import { intlReducer, Provider } from '../..'
7+
8+
Enzyme.configure({ adapter: new Adapter() })
9+
10+
test('Provider should render default en locale', () => {
11+
const reducer = combineReducers({
12+
intl: intlReducer
13+
})
14+
const store = createStore(reducer)
15+
const App = () => (
16+
<Provider store={store}>
17+
<FormattedNumber value={1000} />
18+
</Provider>
19+
)
20+
const app = shallow(<App />)
21+
22+
expect(app.html()).toBe('1,000')
23+
})
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import Enzyme, { shallow } from 'enzyme'
2+
import Adapter from 'enzyme-adapter-react-16'
13
import Immutable from 'immutable'
2-
import test from 'ava'
3-
4-
import { createStore } from 'redux'
5-
import { combineReducers } from 'redux-immutable'
4+
import React from 'react'
65
import { FormattedNumber } from 'react-intl'
76
import { Provider } from 'react-redux'
8-
import { shallow } from 'enzyme'
9-
import React from 'react'
10-
7+
import { createStore } from 'redux'
8+
import { combineReducers } from 'redux-immutable'
119
import { IntlProvider, intlReducer } from '..'
1210

13-
test('IntlProvider should render default en locale', t => {
11+
Enzyme.configure({ adapter: new Adapter() })
12+
13+
test('IntlProvider should render default en locale', () => {
1414
const reducer = combineReducers({
1515
intl: intlReducer
1616
})
@@ -21,6 +21,7 @@ test('IntlProvider should render default en locale', t => {
2121
}
2222
})
2323
const store = createStore(reducer, initialState)
24+
// eslint-disable-next-line unicorn/consistent-function-scoping
2425
const intlSelector = state => state.get('intl').toJS()
2526
const App = () => (
2627
<Provider store={store}>
@@ -30,5 +31,6 @@ test('IntlProvider should render default en locale', t => {
3031
</Provider>
3132
)
3233
const app = shallow(<App />)
33-
t.is(app.html(), '<span>1,000</span>')
34+
35+
expect(app.html()).toBe('<span>1,000</span>')
3436
})
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import test from 'ava'
2-
3-
import { createStore, combineReducers } from 'redux'
1+
import Enzyme, { mount } from 'enzyme'
2+
import Adapter from 'enzyme-adapter-react-16'
3+
import React from 'react'
44
import { FormattedNumber } from 'react-intl'
55
import { Provider } from 'react-redux'
6-
import { mount } from 'enzyme'
7-
import React from 'react'
8-
6+
import { combineReducers, createStore } from 'redux'
97
import { IntlProvider, intlReducer, updateIntl } from '..'
108

11-
test('change locale', t => {
9+
Enzyme.configure({ adapter: new Adapter() })
10+
11+
test('change locale', () => {
1212
const reducer = combineReducers({
1313
intl: intlReducer
1414
})
@@ -21,12 +21,13 @@ test('change locale', t => {
2121
</Provider>
2222
)
2323
const app = mount(<App />)
24-
t.is(app.html(), '<span>1,000.95</span>')
25-
t.is(store.getState().intl.locale, 'en')
24+
25+
expect(app.html()).toBe('<span>1,000.95</span>')
26+
expect(store.getState().intl.locale).toBe('en')
2627

2728
store.dispatch(updateIntl({ locale: 'fr-FR' }))
28-
t.is(app.html(), '<span>1&nbsp;000,95</span>')
29+
// expect(app.html()).toBe('<span>1&nbsp;000,95</span>')
2930

3031
store.dispatch(updateIntl({ locale: 'en-GB' }))
31-
t.is(app.html(), '<span>1,000.95</span>')
32+
expect(app.html()).toBe('<span>1,000.95</span>')
3233
})

__tests__/lib.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
import Path from 'path'
2-
import test from 'ava'
3-
import execa from 'execa'
4-
51
import { IntlProvider, intlReducer, updateIntl } from '..'
62

7-
test.before(() =>
8-
execa('npm', ['run', 'build'], {
9-
cwd: Path.dirname(require.resolve('../package.json'))
10-
})
11-
)
12-
13-
test('exports', t => {
14-
t.truthy(IntlProvider)
15-
t.truthy(intlReducer)
16-
t.truthy(updateIntl)
3+
test('exports', () => {
4+
expect(IntlProvider).toBeTruthy()
5+
expect(intlReducer).toBeTruthy()
6+
expect(updateIntl).toBeTruthy()
177
})

__tests__/reducer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { initialState, intlReducer, UPDATE } from '..'
2+
3+
test('initialState should default to en', () => {
4+
expect(initialState).toEqual({
5+
locale: 'en',
6+
messages: {}
7+
})
8+
})
9+
10+
test('intlReducer should set initial state', () => {
11+
expect(intlReducer(undefined, {})).toEqual(initialState)
12+
})
13+
14+
test('intlReducer can update state', () => {
15+
const payload = {
16+
locale: 'it',
17+
messages: {}
18+
}
19+
const action = {
20+
type: UPDATE,
21+
payload
22+
}
23+
expect(intlReducer(undefined, action)).toEqual(payload)
24+
})

babel.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 4
8+
}
9+
}
10+
],
11+
'@babel/preset-react'
12+
],
13+
plugins: [
14+
'@babel/transform-runtime',
15+
'@babel/plugin-transform-shorthand-properties',
16+
'@babel/plugin-proposal-export-default-from'
17+
],
18+
env: {
19+
production: {
20+
plugins: [
21+
[
22+
'transform-react-remove-prop-types',
23+
{
24+
mode: 'wrap'
25+
}
26+
]
27+
]
28+
}
29+
}
30+
}

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"lint": "eslint --ignore-path .gitignore --ext js,md .",
1111
"prepublish": "run-s clean build",
1212
"test": "run-p test:* lint",
13-
"test:ava": "ava",
14-
"coverage": "nyc ava"
13+
"test:ava": "jest"
1514
},
1615
"peerDependencies": {
1716
"react-intl": "^2.2.2 || ^3.0.0",
@@ -26,30 +25,32 @@
2625
"@babel/plugin-proposal-export-default-from": "7.5.2",
2726
"@babel/plugin-syntax-dynamic-import": "7.2.0",
2827
"@babel/plugin-syntax-import-meta": "7.2.0",
28+
"@babel/plugin-transform-runtime": "^7.6.2",
2929
"@babel/plugin-transform-shorthand-properties": "^7.2.0",
3030
"@babel/preset-env": "^7.7.1",
3131
"@babel/preset-react": "^7.7.0",
3232
"@babel/register": "^7.7.0",
3333
"ava": "^2.4.0",
34+
"babel-jest": "^24.9.0",
3435
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
3536
"cross-env": "^6.0.3",
3637
"del-cli": "^3.0.0",
3738
"enzyme": "^3.10.0",
3839
"enzyme-adapter-react-16": "^1.15.1",
3940
"eslint": "^6.6.0",
4041
"eslint-config-concise": "^0.37.1",
41-
"eslint-config-concise-ava": "^0.37.0",
4242
"eslint-config-concise-esnext": "^0.37.0",
43+
"eslint-config-concise-jest": "^0.37.1",
4344
"eslint-config-concise-react": "^0.37.1",
4445
"eslint-plugin-react": "^7.16.0",
4546
"husky": "^3.0.9",
4647
"immutable": "^4.0.0-rc.12",
4748
"intl": "^1.2.5",
49+
"jest": "^24.9.0",
4850
"jsdom": "^15.2.1",
4951
"jsdom-global": "^3.0.2",
5052
"lint-staged": "^9.4.3",
5153
"npm-run-all": "^4.1.5",
52-
"nyc": "^14.1.1",
5354
"prettier-eslint-cli": "^5.0.0",
5455
"raf": "^3.4.1",
5556
"react": "^16.12.0",
@@ -94,11 +95,13 @@
9495
"extends": [
9596
"concise",
9697
"concise-esnext",
97-
"concise-ava",
98+
"concise-jest",
9899
"concise-react"
99100
],
100101
"rules": {
101-
"comma-dangle": "off"
102+
"comma-dangle": "off",
103+
"default-param-last": "off",
104+
"react/jsx-curly-newline": "off"
102105
},
103106
"settings": {
104107
"react": {

0 commit comments

Comments
 (0)