Add tests for createTypeAnnotationBasedOnTypeof
This commit is contained in:
parent
4ca35ef8b9
commit
d915f31bcb
@ -0,0 +1,58 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`builders flow createTypeAnnotationBasedOnTypeof function 1`] = `
|
||||
Object {
|
||||
"id": Object {
|
||||
"name": "Function",
|
||||
"type": "Identifier",
|
||||
},
|
||||
"type": "GenericTypeAnnotation",
|
||||
"typeParameters": null,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`builders flow createTypeAnnotationBasedOnTypeof number 1`] = `
|
||||
Object {
|
||||
"type": "NumberTypeAnnotation",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`builders flow createTypeAnnotationBasedOnTypeof object 1`] = `
|
||||
Object {
|
||||
"id": Object {
|
||||
"name": "Object",
|
||||
"type": "Identifier",
|
||||
},
|
||||
"type": "GenericTypeAnnotation",
|
||||
"typeParameters": null,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`builders flow createTypeAnnotationBasedOnTypeof string 1`] = `
|
||||
Object {
|
||||
"type": "StringTypeAnnotation",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`builders flow createTypeAnnotationBasedOnTypeof symbol 1`] = `
|
||||
Object {
|
||||
"id": Object {
|
||||
"name": "Symbol",
|
||||
"type": "Identifier",
|
||||
},
|
||||
"type": "GenericTypeAnnotation",
|
||||
"typeParameters": null,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`builders flow createTypeAnnotationBasedOnTypeof true 1`] = `
|
||||
Object {
|
||||
"type": "BooleanTypeAnnotation",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`builders flow createTypeAnnotationBasedOnTypeof undefined 1`] = `
|
||||
Object {
|
||||
"type": "VoidTypeAnnotation",
|
||||
}
|
||||
`;
|
||||
@ -0,0 +1,31 @@
|
||||
import { createTypeAnnotationBasedOnTypeof } from "@babel/types";
|
||||
|
||||
describe("builders", function() {
|
||||
describe("flow", function() {
|
||||
describe("createTypeAnnotationBasedOnTypeof", function() {
|
||||
const values = {
|
||||
string: typeof "string",
|
||||
number: typeof 123,
|
||||
true: typeof true,
|
||||
object: typeof {},
|
||||
undefined: typeof undefined,
|
||||
function: typeof function() {},
|
||||
symbol: typeof Symbol(),
|
||||
};
|
||||
|
||||
for (const name in values) {
|
||||
const value = values[name];
|
||||
it(name, function() {
|
||||
const result = createTypeAnnotationBasedOnTypeof(value);
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
}
|
||||
|
||||
it("invalid", function() {
|
||||
expect(() =>
|
||||
createTypeAnnotationBasedOnTypeof("thisdoesnotexist"),
|
||||
).toThrow(Error);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user