Skip to content

Commit

Permalink
Polyfill Intl for test
Browse files Browse the repository at this point in the history
  • Loading branch information
ratson committed Jul 26, 2018
1 parent 9de83a6 commit 8c93092
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
12 changes: 6 additions & 6 deletions examples/multiple-languages/src/index.js
Expand Up @@ -39,13 +39,13 @@ class App extends React.Component {
<IntlProvider>
<div>
<Greeting />
<p>
<button type="button" onClick={this.handleLoadlLocales}>
<p>
<button type="button" onClick={this.handleLoadlLocales}>
Local locales
</button>{' '}
<SwitchLocale />
</p>
<DevTools />
</button>{' '}
<SwitchLocale />
</p>
<DevTools />
</div>
</IntlProvider>
</Provider>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -28,7 +28,7 @@
"@babel/preset-react": "^7.0.0-beta.54",
"@babel/preset-stage-1": "^7.0.0-beta.54",
"@babel/register": "^7.0.0-beta.54",
"ava": "^0.25.0",
"ava": "^1.0.0-beta.6",
"babel-plugin-transform-react-remove-prop-types": "^0.4.13",
"cross-env": "^5.2.0",
"del-cli": "^1.1.0",
Expand All @@ -42,6 +42,7 @@
"eslint-plugin-react": "^7.10.0",
"husky": "^0.14.3",
"immutable": "^3.8.2",
"intl": "^1.2.5",
"jsdom": "^11.11.0",
"jsdom-global": "^3.0.2",
"lerna": "^3.0.0-beta.21",
Expand Down
3 changes: 3 additions & 0 deletions test/helpers/enzyme-config.js
@@ -1,4 +1,7 @@
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import IntlPolyfill from 'intl'

global.Intl = IntlPolyfill

Enzyme.configure({ adapter: new Adapter() })
13 changes: 7 additions & 6 deletions test/integrated.spec.js
@@ -1,7 +1,7 @@
import test from 'ava'

import { createStore, combineReducers } from 'redux'
import { FormattedDate } from 'react-intl'
import { FormattedNumber } from 'react-intl'
import { Provider } from 'react-redux'
import { mount } from 'enzyme'
import React from 'react'
Expand All @@ -16,16 +16,17 @@ test('change locale', t => {
const App = () => (
<Provider store={store}>
<IntlProvider>
<FormattedDate value={new Date(0)} />
<FormattedNumber value={1000.95} />
</IntlProvider>
</Provider>
)
const app = mount(<App />)
t.is(app.html(), '<span>1/1/1970</span>')
t.is(app.html(), '<span>1,000.95</span>')
t.is(store.getState().intl.locale, 'en')

store.dispatch(updateIntl({ locale: 'it' }))
t.is(app.html(), '<span>1970-1-1</span>')
store.dispatch(updateIntl({ locale: 'fr-FR' }))
t.is(app.html(), '<span>1&nbsp;000,95</span>')

store.dispatch(updateIntl({ locale: 'en-GB' }))
t.is(app.html(), '<span>1/1/1970</span>')
t.is(app.html(), '<span>1,000.95</span>')
})

0 comments on commit 8c93092

Please sign in to comment.