/
normalize-options.spec.js
97 lines (96 loc) 路 3.2 KB
/
normalize-options.spec.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import _normalizeOptions from "../lib/normalize-options.js";
const normalizeOptions = _normalizeOptions.default;
describe("normalize options", () => {
(process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => {
it("should throw on unknown options", () => {
expect(() => normalizeOptions({ allowNamespace: true })).toThrowError(
"@babel/preset-typescript: 'allowNamespace' is not a valid top-level option.\n- Did you mean 'allowNamespaces'?",
);
});
it.each([
"allExtensions",
"allowNamespaces",
"isTSX",
"onlyRemoveTypeImports",
"optimizeConstEnums",
])("should throw when `%p` is not a boolean", optionName => {
expect(() => normalizeOptions({ [optionName]: 0 })).toThrow(
`@babel/preset-typescript: '${optionName}' option must be a boolean.`,
);
});
it.each(["jsxPragma", "jsxPragmaFrag"])(
"should throw when `%p` is not a string",
optionName => {
expect(() => normalizeOptions({ [optionName]: 0 })).toThrow(
`@babel/preset-typescript: '${optionName}' option must be a string.`,
);
},
);
it("should not throw when options is not defined", () => {
expect(() => normalizeOptions()).not.toThrowError();
});
it("default values", () => {
expect(normalizeOptions({})).toMatchInlineSnapshot(`
Object {
"allExtensions": false,
"allowNamespaces": true,
"disallowAmbiguousJSXLike": false,
"isTSX": false,
"jsxPragma": "React",
"jsxPragmaFrag": "React.Fragment",
"onlyRemoveTypeImports": true,
"optimizeConstEnums": false,
}
`);
});
});
(process.env.BABEL_8_BREAKING ? describe.skip : describe)("Babel 7", () => {
it("should not throw on unknown options", () => {
expect(() =>
normalizeOptions({ allowNamespace: true }),
).not.toThrowError();
});
it.each(["allowDeclareFields", "allowNamespaces", "onlyRemoveTypeImports"])(
"should not throw when `%p` is not a boolean",
optionName => {
expect(() => normalizeOptions({ [optionName]: 0 })).not.toThrowError();
},
);
it.each(["jsxPragma"])(
"should throw when `%p` is not a string",
optionName => {
expect(() => normalizeOptions({ [optionName]: 0 })).not.toThrowError();
},
);
it.each(["allExtensions", "isTSX", "optimizeConstEnums"])(
"should throw when `%p` is not a boolean",
optionName => {
expect(() => normalizeOptions({ [optionName]: 0 })).toThrow(
`@babel/preset-typescript: '${optionName}' option must be a boolean.`,
);
},
);
it.each(["jsxPragmaFrag"])(
"should throw when `%p` is not a string",
optionName => {
expect(() => normalizeOptions({ [optionName]: 0 })).toThrow(
`@babel/preset-typescript: '${optionName}' option must be a string.`,
);
},
);
it("default values", () => {
expect(normalizeOptions({})).toMatchInlineSnapshot(`
Object {
"allExtensions": false,
"allowNamespaces": true,
"disallowAmbiguousJSXLike": false,
"isTSX": false,
"jsxPragma": undefined,
"jsxPragmaFrag": "React.Fragment",
"onlyRemoveTypeImports": undefined,
"optimizeConstEnums": false,
}
`);
});
});
});