Debian Codegraph @

packages/babel-preset-typescript/test/normalize-options.skip-bundled.js

raw symbols SCIP
1 import _normalizeOptions from "../lib/normalize-options.js";
2 const normalizeOptions = _normalizeOptions.default || _normalizeOptions;
3
4 describe("normalize options", () => {
5 (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => {
6 it("should throw on unknown options", () => {
7 expect(() => normalizeOptions({ allowNamespace: true })).toThrow(
8 "@babel/preset-typescript: 'allowNamespace' is not a valid top-level option.\n- Did you mean 'allowNamespaces'?",
9 );
10 });
11 it.each([
12 "allExtensions",
13 "allowNamespaces",
14 "isTSX",
15 "onlyRemoveTypeImports",
16 "optimizeConstEnums",
17 ])("should throw when `%p` is not a boolean", optionName => {
18 expect(() => normalizeOptions({ [optionName]: 0 })).toThrow(
19 `@babel/preset-typescript: '${optionName}' option must be a boolean.`,
20 );
21 });
22 it.each(["jsxPragma", "jsxPragmaFrag"])(
23 "should throw when `%p` is not a string",
24 optionName => {
25 expect(() => normalizeOptions({ [optionName]: 0 })).toThrow(
26 `@babel/preset-typescript: '${optionName}' option must be a string.`,
27 );
28 },
29 );
30 it("should not throw when options is not defined", () => {
31 expect(() => normalizeOptions()).not.toThrow();
32 });
33 it("default values", () => {
34 expect(normalizeOptions({})).toMatchInlineSnapshot(`
35 Object {
36 "allExtensions": false,
37 "allowNamespaces": true,
38 "disallowAmbiguousJSXLike": false,
39 "isTSX": false,
40 "jsxPragma": "React",
41 "jsxPragmaFrag": "React.Fragment",
42 "onlyRemoveTypeImports": true,
43 "optimizeConstEnums": false,
44 }
45 `);
46 });
47 });
48 (process.env.BABEL_8_BREAKING ? describe.skip : describe)("Babel 7", () => {
49 it("should not throw on unknown options", () => {
50 expect(() => normalizeOptions({ allowNamespace: true })).not.toThrow();
51 });
52 it.each(["allowDeclareFields", "allowNamespaces", "onlyRemoveTypeImports"])(
53 "should not throw when `%p` is not a boolean",
54 optionName => {
55 expect(() => normalizeOptions({ [optionName]: 0 })).not.toThrow();
56 },
57 );
58 it.each(["jsxPragma"])(
59 "should throw when `%p` is not a string",
60 optionName => {
61 expect(() => normalizeOptions({ [optionName]: 0 })).not.toThrow();
62 },
63 );
64 it.each(["allExtensions", "isTSX", "optimizeConstEnums"])(
65 "should throw when `%p` is not a boolean",
66 optionName => {
67 expect(() => normalizeOptions({ [optionName]: 0 })).toThrow(
68 `@babel/preset-typescript: '${optionName}' option must be a boolean.`,
69 );
70 },
71 );
72 it.each(["jsxPragmaFrag"])(
73 "should throw when `%p` is not a string",
74 optionName => {
75 expect(() => normalizeOptions({ [optionName]: 0 })).toThrow(
76 `@babel/preset-typescript: '${optionName}' option must be a string.`,
77 );
78 },
79 );
80 it("default values", () => {
81 expect(normalizeOptions({})).toMatchInlineSnapshot(`
82 Object {
83 "allExtensions": false,
84 "allowNamespaces": true,
85 "disallowAmbiguousJSXLike": false,
86 "isTSX": false,
87 "jsxPragma": undefined,
88 "jsxPragmaFrag": "React.Fragment",
89 "onlyRemoveTypeImports": undefined,
90 "optimizeConstEnums": false,
91 }
92 `);
93 });
94 });
95 });