-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
64 lines (54 loc) · 1.41 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import test from 'ava';
// Translations
import sameKeys from './fixtures/same-keys';
import differentKeys from './fixtures/different-keys';
import validi18n from '.';
const I18n = {
translations: {
samesame: {...sameKeys},
different: {...differentKeys}
}
};
const invalidI18nDiff = {a: {aa: 1}, b: {bb: 2}};
const invalidI18nSame = {a: {aa: 1}, b: {aa: 2}};
test('argument type', t => {
const err = t.throws(() => {
validi18n(123);
}, TypeError);
t.is(err.message, 'Expected an object, got number');
});
test('dummy object with same keys', t => {
t.true(validi18n(invalidI18nSame));
});
test('dummy object with diff keys', t => {
t.false(validi18n(invalidI18nDiff));
});
test('argument type in validi18n.diff', t => {
const err = t.throws(() => {
validi18n.diff(invalidI18nDiff);
}, TypeError);
t.is(err.message, 'Expected an object, got undefined');
});
test('empty object', t => {
t.true(validi18n({}));
});
test('same translations', t => {
t.true(validi18n(I18n.translations.samesame));
});
test('different translations keys in translations', t => {
t.false(validi18n(I18n.translations.different));
});
test('differences', t => {
t.deepEqual(
validi18n.diffs(...validi18n.formatTranslations(I18n.translations)),
{
samesame: [
'de.form.validation.tooShort',
'de.form.validation.tooLong',
'de.form.validation.required',
'de.form.validation.notValid'
],
different: []
}
);
});