Skip to content

Commit 61edc00

Browse files
committed
test: update snapshots and imports
1 parent d91338a commit 61edc00

21 files changed

+90
-71
lines changed

.eslintrc

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,11 @@
3636
"@typescript-eslint/explicit-function-return-type": "off",
3737
"@typescript-eslint/no-explicit-any": "off",
3838
"@typescript-eslint/no-non-null-assertion": "off"
39-
}
39+
},
40+
"overrides": [
41+
{
42+
"files": ["*.test.ts", "*.test.tsx"],
43+
"env": { "jest": true, "node": true }
44+
}
45+
]
4046
}

babel.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
*/
88

99
module.exports = {
10-
presets: ['module:metro-react-native-babel-preset'],
10+
presets: [
11+
'module:metro-react-native-babel-preset',
12+
'@babel/preset-typescript',
13+
],
1114
};

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"build": "tsc",
3131
"cldr": "gulp cldr",
3232
"coverage": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
33-
"lint": "tsc --noEmit && eslint src --ext .ts,.tsx",
33+
"lint": "tsc --noEmit && eslint src test --ext .ts,.tsx",
3434
"test": "jest --coverage"
3535
},
3636
"dependencies": {
@@ -40,8 +40,10 @@
4040
},
4141
"devDependencies": {
4242
"@babel/core": "^7.8.4",
43+
"@babel/preset-typescript": "^7.8.3",
4344
"@types/cldrjs": "^0.4.22",
4445
"@types/globalize": "^0.0.35",
46+
"@types/jest": "^25.1.2",
4547
"@types/react": "^16.9.19",
4648
"@types/react-native": "^0.61.14",
4749
"@typescript-eslint/eslint-plugin": "^2.19.2",

src/__tests__/globalize.test.js src/__tests__/globalize.test.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
* https://github.com/joshswan/react-native-globalize/blob/master/LICENSE
77
*/
88

9-
import Globalize from '../globalize';
9+
import { Globalize } from '../globalize';
1010

1111
describe('Globalize', () => {
1212
describe('static availableLocales()', () => {
1313
test('returns list of loaded locales', () => {
14+
/* eslint-disable no-multi-spaces */
1415
expect(Globalize.availableLocales().sort()).toEqual([
1516
'am', // Amharic
1617
'ar', // Arabic
@@ -67,6 +68,7 @@ describe('Globalize', () => {
6768
'zh-Hans', // Chinese (Simplified)
6869
'zh-Hant', // Chinese (Traditional)
6970
]);
71+
/* eslint-enable */
7072
});
7173
});
7274

@@ -101,8 +103,8 @@ describe('Globalize', () => {
101103
const spy = jest.spyOn(console, 'warn');
102104
const messageFormatter = globalize.getMessageFormatter('test');
103105

104-
expect(spy).toHaveBeenCalledWith('[Globalize] Missing message: test!');
105-
expect(messageFormatter()).toEqual('test');
106+
expect(spy).toHaveBeenCalledWith('[Globalize] Missing message: "test"!');
107+
expect(messageFormatter()).toEqual('"test"');
106108

107109
spy.mockRestore();
108110
});
@@ -114,7 +116,7 @@ describe('Globalize', () => {
114116
const messageFormatter = globalize.getMessageFormatter('test');
115117

116118
expect(spy).not.toHaveBeenCalled();
117-
expect(messageFormatter()).toEqual('test');
119+
expect(messageFormatter()).toEqual('"test"');
118120

119121
spy.mockRestore();
120122
});
@@ -134,7 +136,7 @@ describe('Globalize', () => {
134136
const globalize = new Globalize('en', 'USD', { warnOnMissingMessage: false });
135137
const messageFormatter = globalize.getMessageFormatter(['test', 'key']);
136138

137-
expect(messageFormatter()).toEqual('test/key');
139+
expect(messageFormatter()).toEqual('["test","key"]');
138140
});
139141

140142
test('outputs defaultMessage option if key does not exist', () => {

src/components/__tests__/FormattedCurrency.test.js src/components/__tests__/FormattedCurrency.test.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
*/
88

99
import React from 'react';
10-
import createComponentWithGlobalize from '../../../utils/createComponentWithGlobalize';
11-
import FormattedCurrency from '../FormattedCurrency';
10+
import createWithGlobalize from '../../../test/createWithGlobalize';
11+
import { FormattedCurrency } from '../FormattedCurrency';
1212

1313
describe('<FormattedCurrency />', () => {
1414
test('renders correctly', () => {
15-
const tree = createComponentWithGlobalize(<FormattedCurrency value={10} />).toJSON();
15+
const tree = createWithGlobalize(<FormattedCurrency value={10} />).toJSON();
1616

1717
expect(tree).toMatchSnapshot();
1818
});

src/components/__tests__/FormattedDate.test.js src/components/__tests__/FormattedDate.test.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
*/
88

99
import React from 'react';
10-
import createComponentWithGlobalize from '../../../utils/createComponentWithGlobalize';
11-
import FormattedDate from '../FormattedDate';
10+
import createWithGlobalize from '../../../test/createWithGlobalize';
11+
import { FormattedDate } from '../FormattedDate';
1212

1313
const date = new Date(2019, 0, 1);
1414

1515
describe('<FormattedDate />', () => {
1616
test('renders correctly', () => {
17-
const tree = createComponentWithGlobalize(<FormattedDate skeleton="yMd" value={date} />).toJSON();
17+
const tree = createWithGlobalize(<FormattedDate skeleton="yMd" value={date} />).toJSON();
1818

1919
expect(tree).toMatchSnapshot();
2020
});

src/components/__tests__/FormattedMessage.test.js src/components/__tests__/FormattedMessage.test.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import React from 'react';
1010
import { Text } from 'react-native';
11-
import createComponentWithGlobalize from '../../../utils/createComponentWithGlobalize';
12-
import FormattedMessage from '../FormattedMessage';
11+
import createWithGlobalize from '../../../test/createWithGlobalize';
12+
import { FormattedMessage } from '../FormattedMessage';
1313

1414
const messages = {
1515
en: {
@@ -21,26 +21,26 @@ const messages = {
2121

2222
describe('<FormattedMessage />', () => {
2323
test('renders correctly', () => {
24-
const tree = createComponentWithGlobalize(<FormattedMessage message="test" />, { currency: 'USD', locale: 'en', messages }).toJSON();
24+
const tree = createWithGlobalize(<FormattedMessage message="test" />, { currency: 'USD', locale: 'en', messages }).toJSON();
2525

2626
expect(tree).toMatchSnapshot();
2727
});
2828

2929
describe('values', () => {
3030
test('replaces variables using values prop', () => {
31-
const tree = createComponentWithGlobalize(<FormattedMessage message="hello" values={{ name: 'Josh' }} />, { currency: 'USD', locale: 'en', messages }).toJSON();
31+
const tree = createWithGlobalize(<FormattedMessage message="hello" values={{ name: 'Josh' }} />, { currency: 'USD', locale: 'en', messages }).toJSON();
3232

3333
expect(tree).toMatchSnapshot();
3434
});
3535

3636
test('uses props passed directly to component', () => {
37-
const tree = createComponentWithGlobalize(<FormattedMessage message="hello" name="Josh" />, { currency: 'USD', locale: 'en', messages }).toJSON();
37+
const tree = createWithGlobalize(<FormattedMessage message="hello" name="Josh" />, { currency: 'USD', locale: 'en', messages }).toJSON();
3838

3939
expect(tree).toMatchSnapshot();
4040
});
4141

4242
test('renders component values', () => {
43-
const tree = createComponentWithGlobalize(<FormattedMessage message="date" date={<Text>1/1/2019</Text>} />, { currency: 'USD', locale: 'en', messages }).toJSON();
43+
const tree = createWithGlobalize(<FormattedMessage message="date" date={<Text>1/1/2019</Text>} />, { currency: 'USD', locale: 'en', messages }).toJSON();
4444

4545
expect(tree).toMatchSnapshot();
4646
});

src/components/__tests__/FormattedNumber.test.js src/components/__tests__/FormattedNumber.test.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
*/
88

99
import React from 'react';
10-
import createComponentWithGlobalize from '../../../utils/createComponentWithGlobalize';
11-
import FormattedNumber from '../FormattedNumber';
10+
import createWithGlobalize from '../../../test/createWithGlobalize';
11+
import { FormattedNumber } from '../FormattedNumber';
1212

1313
describe('<FormattedNumber />', () => {
1414
test('renders correctly', () => {
15-
const tree = createComponentWithGlobalize(<FormattedNumber value={1000} />).toJSON();
15+
const tree = createWithGlobalize(<FormattedNumber value={1000} />).toJSON();
1616

1717
expect(tree).toMatchSnapshot();
1818
});

src/components/__tests__/FormattedPlural.test.js src/components/__tests__/FormattedPlural.test.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
*/
88

99
import React from 'react';
10-
import createComponentWithGlobalize from '../../../utils/createComponentWithGlobalize';
11-
import FormattedPlural from '../FormattedPlural';
10+
import createWithGlobalize from '../../../test/createWithGlobalize';
11+
import { FormattedPlural } from '../FormattedPlural';
1212

1313
describe('<FormattedPlural />', () => {
1414
test('renders correctly', () => {
15-
const tree = createComponentWithGlobalize(<FormattedPlural value={1} zero=":(" other=":)" />).toJSON();
15+
const tree = createWithGlobalize(<FormattedPlural value={1} zero=":(" other=":)" />).toJSON();
1616

1717
expect(tree).toMatchSnapshot();
1818
});

src/components/__tests__/FormattedRelativeTime.test.js src/components/__tests__/FormattedRelativeTime.test.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88

99
import React from 'react';
10-
import createComponentWithGlobalize from '../../../utils/createComponentWithGlobalize';
11-
import FormattedRelativeTime from '../FormattedRelativeTime';
10+
import createWithGlobalize from '../../../test/createWithGlobalize';
11+
import { FormattedRelativeTime } from '../FormattedRelativeTime';
1212

1313
describe('<FormattedRelativeTime />', () => {
1414
const dateNow = Date.now;
@@ -22,28 +22,28 @@ describe('<FormattedRelativeTime />', () => {
2222
});
2323

2424
test('renders correctly', () => {
25-
const tree = createComponentWithGlobalize(<FormattedRelativeTime value={5} unit="minute" />).toJSON();
25+
const tree = createWithGlobalize(<FormattedRelativeTime value={5} unit="minute" />).toJSON();
2626

2727
expect(tree).toMatchSnapshot();
2828
});
2929

3030
describe('unit', () => {
3131
test('supports best unit option', () => {
32-
const tree = createComponentWithGlobalize(<FormattedRelativeTime value={new Date('2015-01-01T00:00:00Z')} unit="best" />).toJSON();
32+
const tree = createWithGlobalize(<FormattedRelativeTime value={new Date('2015-01-01T00:00:00Z')} unit="best" />).toJSON();
3333

3434
expect(tree).toMatchSnapshot();
3535
});
3636

3737
test('renders when best unit selected and non-date value used', () => {
38-
const tree = createComponentWithGlobalize(<FormattedRelativeTime value={10} unit="best" />).toJSON();
38+
const tree = createWithGlobalize(<FormattedRelativeTime value={10} unit="best" />).toJSON();
3939

4040
expect(tree).toMatchSnapshot();
4141
});
4242
});
4343

4444
describe('value', () => {
4545
test('supports date instances for value', () => {
46-
const tree = createComponentWithGlobalize(<FormattedRelativeTime value={new Date('2017-01-01T00:00:00Z')} unit="day" />).toJSON();
46+
const tree = createWithGlobalize(<FormattedRelativeTime value={new Date('2017-01-01T00:00:00Z')} unit="day" />).toJSON();
4747

4848
expect(tree).toMatchSnapshot();
4949
});

src/components/__tests__/FormattedUnit.test.js src/components/__tests__/FormattedUnit.test.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
*/
88

99
import React from 'react';
10-
import createComponentWithGlobalize from '../../../utils/createComponentWithGlobalize';
11-
import Globalize from '../../globalize';
12-
import FormattedUnit from '../FormattedUnit';
10+
import createWithGlobalize from '../../../test/createWithGlobalize';
11+
import { Globalize } from '../../globalize';
12+
import { FormattedUnit } from '../FormattedUnit';
1313

1414
describe('<FormattedUnit />', () => {
1515
test('renders correctly', () => {
16-
const tree = createComponentWithGlobalize((
16+
const tree = createWithGlobalize((
1717
<FormattedUnit
1818
unit="mile-per-hour"
1919
value={75}
@@ -30,7 +30,7 @@ describe('<FormattedUnit />', () => {
3030
useGrouping: false,
3131
});
3232

33-
const tree = createComponentWithGlobalize((
33+
const tree = createWithGlobalize((
3434
<FormattedUnit
3535
form="narrow"
3636
numberFormatter={numberFormatter}

src/components/__tests__/__snapshots__/FormattedCurrency.test.js.snap src/components/__tests__/__snapshots__/FormattedCurrency.test.tsx.snap

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exports[`<FormattedCurrency /> renders correctly 1`] = `
66
accessible={true}
77
adjustsFontSizeToFit={false}
88
allowFontScaling={true}
9-
style={null}
109
>
1110
$10.00
1211
</Text>

src/components/__tests__/__snapshots__/FormattedDate.test.js.snap src/components/__tests__/__snapshots__/FormattedDate.test.tsx.snap

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exports[`<FormattedDate /> renders correctly 1`] = `
66
accessible={true}
77
adjustsFontSizeToFit={false}
88
allowFontScaling={true}
9-
style={null}
109
>
1110
1/1/2019
1211
</Text>

src/components/__tests__/__snapshots__/FormattedMessage.test.js.snap src/components/__tests__/__snapshots__/FormattedMessage.test.tsx.snap

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exports[`<FormattedMessage /> renders correctly 1`] = `
66
accessible={true}
77
adjustsFontSizeToFit={false}
88
allowFontScaling={true}
9-
style={null}
109
>
1110
Test
1211
</Text>
@@ -18,7 +17,6 @@ exports[`<FormattedMessage /> values renders component values 1`] = `
1817
accessible={true}
1918
adjustsFontSizeToFit={false}
2019
allowFontScaling={true}
21-
style={null}
2220
>
2321
Todays date is
2422
<Text>
@@ -33,7 +31,6 @@ exports[`<FormattedMessage /> values replaces variables using values prop 1`] =
3331
accessible={true}
3432
adjustsFontSizeToFit={false}
3533
allowFontScaling={true}
36-
style={null}
3734
>
3835
Hey Josh!
3936
</Text>
@@ -45,7 +42,6 @@ exports[`<FormattedMessage /> values uses props passed directly to component 1`]
4542
accessible={true}
4643
adjustsFontSizeToFit={false}
4744
allowFontScaling={true}
48-
style={null}
4945
>
5046
Hey Josh!
5147
</Text>

src/components/__tests__/__snapshots__/FormattedNumber.test.js.snap src/components/__tests__/__snapshots__/FormattedNumber.test.tsx.snap

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exports[`<FormattedNumber /> renders correctly 1`] = `
66
accessible={true}
77
adjustsFontSizeToFit={false}
88
allowFontScaling={true}
9-
style={null}
109
>
1110
1,000
1211
</Text>

src/components/__tests__/__snapshots__/FormattedPlural.test.js.snap src/components/__tests__/__snapshots__/FormattedPlural.test.tsx.snap

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exports[`<FormattedPlural /> renders correctly 1`] = `
66
accessible={true}
77
adjustsFontSizeToFit={false}
88
allowFontScaling={true}
9-
style={null}
109
>
1110
:)
1211
</Text>

src/components/__tests__/__snapshots__/FormattedRelativeTime.test.js.snap src/components/__tests__/__snapshots__/FormattedRelativeTime.test.tsx.snap

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exports[`<FormattedRelativeTime /> renders correctly 1`] = `
66
accessible={true}
77
adjustsFontSizeToFit={false}
88
allowFontScaling={true}
9-
style={null}
109
>
1110
in 5 minutes
1211
</Text>
@@ -18,7 +17,6 @@ exports[`<FormattedRelativeTime /> unit renders when best unit selected and non-
1817
accessible={true}
1918
adjustsFontSizeToFit={false}
2019
allowFontScaling={true}
21-
style={null}
2220
>
2321
in 10 seconds
2422
</Text>
@@ -30,7 +28,6 @@ exports[`<FormattedRelativeTime /> unit supports best unit option 1`] = `
3028
accessible={true}
3129
adjustsFontSizeToFit={false}
3230
allowFontScaling={true}
33-
style={null}
3431
>
3532
3 years ago
3633
</Text>
@@ -42,7 +39,6 @@ exports[`<FormattedRelativeTime /> value supports date instances for value 1`] =
4239
accessible={true}
4340
adjustsFontSizeToFit={false}
4441
allowFontScaling={true}
45-
style={null}
4642
>
4743
365 days ago
4844
</Text>

src/components/__tests__/__snapshots__/FormattedUnit.test.js.snap src/components/__tests__/__snapshots__/FormattedUnit.test.tsx.snap

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exports[`<FormattedUnit /> renders correctly 1`] = `
66
accessible={true}
77
adjustsFontSizeToFit={false}
88
allowFontScaling={true}
9-
style={null}
109
>
1110
75 miles per hour
1211
</Text>
@@ -18,7 +17,6 @@ exports[`<FormattedUnit /> uses a custom number formatter function 1`] = `
1817
accessible={true}
1918
adjustsFontSizeToFit={false}
2019
allowFontScaling={true}
21-
style={null}
2220
>
2321
5000.00mi²
2422
</Text>

0 commit comments

Comments
 (0)