babel/packages/babel-preset-flow/test/normalize-options.spec.js
Huáng Jùnliàng 16d83002de
[babel 8] type checking preset-flow options (#12751)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2021-03-26 00:33:02 +01:00

56 lines
2.0 KiB
JavaScript

import normalizeOptions from "../src/normalize-options";
describe("normalize options", () => {
(process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => {
it("should throw on unknown options", () => {
expect(() => normalizeOptions({ al: true }))
.toThrowErrorMatchingInlineSnapshot(`
"@babel/preset-flow: 'al' is not a valid top-level option.
- Did you mean 'all'?"
`);
});
it("should throw on Babel 7 `allowDeclareFields` option", () => {
expect(() =>
normalizeOptions({ allowDeclareFields: true }),
).toThrowErrorMatchingInlineSnapshot(
`"@babel/preset-flow: Since Babel 8, \`declare property: A\` is always supported, and the \\"allowDeclareFields\\" option is no longer available. Please remove it from your config."`,
);
});
it.each(["all"])("should throw when `%p` is not a boolean", optionName => {
expect(() => normalizeOptions({ [optionName]: 0 })).toThrow(
`@babel/preset-flow: '${optionName}' option must be a boolean.`,
);
});
it("should not throw when options is not defined", () => {
expect(() => normalizeOptions()).not.toThrowError();
});
it("default values", () => {
expect(normalizeOptions({})).toMatchInlineSnapshot(`
Object {
"all": undefined,
}
`);
});
});
(process.env.BABEL_8_BREAKING ? describe.skip : describe)("Babel 7", () => {
it("should not throw on unknown options", () => {
expect(() =>
normalizeOptions({ allDeclareField: true }),
).not.toThrowError();
});
it.each(["all", "allowDeclareFields"])(
"should not throw when `%p` is not a boolean",
optionName => {
expect(() => normalizeOptions({ [optionName]: 0 })).not.toThrowError();
},
);
it("default values", () => {
expect(normalizeOptions({})).toMatchInlineSnapshot(`
Object {
"all": undefined,
"allowDeclareFields": undefined,
}
`);
});
});
});