Debian Codegraph @

packages/babel-types/test/builders/typescript/tsTypeParameter.js

raw
1 import * as t from "../../../lib/index.js";
2
3 describe("builders", function () {
4 describe("typescript", function () {
5 (process.env.BABEL_8_BREAKING ? describe : describe.skip)(
6 "tsTypeParameter",
7 function () {
8 it("accept name as argument for tsTypeParameter", function () {
9 const tsTypeParameter = t.tsTypeParameter(
10 t.tsTypeReference(t.identifier("bar")),
11 t.tsTypeReference(t.identifier("baz")),
12 t.identifier("foo"),
13 );
14 expect(tsTypeParameter).toMatchInlineSnapshot(`
15 Object {
16 "constraint": Object {
17 "type": "TSTypeReference",
18 "typeName": Object {
19 "name": "bar",
20 "type": "Identifier",
21 },
22 "typeParameters": null,
23 },
24 "default": Object {
25 "type": "TSTypeReference",
26 "typeName": Object {
27 "name": "baz",
28 "type": "Identifier",
29 },
30 "typeParameters": null,
31 },
32 "name": Object {
33 "name": "foo",
34 "type": "Identifier",
35 },
36 "type": "TSTypeParameter",
37 }
38 `);
39 });
40 it("throws when name is missing", function () {
41 expect(() => {
42 t.tsTypeParameter(
43 t.tsTypeReference(t.identifier("bar")),
44 t.tsTypeReference(t.identifier("baz")),
45 );
46 }).toThrow(
47 'Property name of TSTypeParameter expected node to be of a type ["Identifier"] but instead got undefined',
48 );
49 });
50 },
51 );
52 (process.env.BABEL_8_BREAKING ? describe.skip : describe)(
53 "tsTypeParameter - Babel 7",
54 function () {
55 it("accept name as argument for tsTypeParameter", function () {
56 const tsTypeParameter = t.tsTypeParameter(
57 t.tsTypeReference(t.identifier("bar")),
58 t.tsTypeReference(t.identifier("baz")),
59 "foo",
60 );
61 expect(tsTypeParameter).toMatchInlineSnapshot(`
62 Object {
63 "constraint": Object {
64 "type": "TSTypeReference",
65 "typeName": Object {
66 "name": "bar",
67 "type": "Identifier",
68 },
69 "typeParameters": null,
70 },
71 "default": Object {
72 "type": "TSTypeReference",
73 "typeName": Object {
74 "name": "baz",
75 "type": "Identifier",
76 },
77 "typeParameters": null,
78 },
79 "name": "foo",
80 "type": "TSTypeParameter",
81 }
82 `);
83 });
84 it("throws when name is missing", function () {
85 expect(() => {
86 t.tsTypeParameter(
87 t.tsTypeReference(t.identifier("bar")),
88 t.tsTypeReference(t.identifier("baz")),
89 );
90 }).toThrow("Property name expected type of string but got undefined");
91 });
92 },
93 );
94 });
95 });