| 1 |
import * as t from "../../../lib/index.js"; |
| 2 |
|
| 3 |
describe("builders", function () { |
| 4 |
describe("typescript", function () { |
| 5 |
describe("tsLiteralType", function () { |
| 6 |
it("accept unary expression", function () { |
| 7 |
expect( |
| 8 |
t.tsLiteralType(t.unaryExpression("-", t.numericLiteral(1))), |
| 9 |
).toMatchSnapshot(); |
| 10 |
expect( |
| 11 |
t.tsLiteralType(t.unaryExpression("-", t.bigIntLiteral("123456789"))), |
| 12 |
).toMatchSnapshot(); |
| 13 |
}); |
| 14 |
it("throws with non-numeric argument", function () { |
| 15 |
expect(() => { |
| 16 |
t.tsLiteralType(t.unaryExpression("-", t.stringLiteral(1))); |
| 17 |
}).toThrow("Property value expected type of string but got number"); |
| 18 |
expect(() => { |
| 19 |
t.tsLiteralType(t.unaryExpression("-", t.objectExpression([]))); |
| 20 |
}).toThrow( |
| 21 |
'Property argument of UnaryExpression expected node to be of a type ["NumericLiteral","BigIntLiteral"] but instead got "ObjectExpression"', |
| 22 |
); |
| 23 |
}); |
| 24 |
}); |
| 25 |
it("throws with bad operator", function () { |
| 26 |
expect(() => { |
| 27 |
t.tsLiteralType(t.unaryExpression("+", t.numericLiteral(1))); |
| 28 |
}).toThrow( |
| 29 |
'Property operator expected value to be one of ["-"] but got "+"', |
| 30 |
); |
| 31 |
|
| 32 |
// should check operator first since it appears first |
| 33 |
expect(() => { |
| 34 |
t.tsLiteralType(t.unaryExpression("+", t.objectExpression([]))); |
| 35 |
}).toThrow( |
| 36 |
'Property operator expected value to be one of ["-"] but got "+"', |
| 37 |
); |
| 38 |
|
| 39 |
expect(() => { |
| 40 |
t.tsLiteralType(t.unaryExpression("~", t.numericLiteral(1))); |
| 41 |
}).toThrow( |
| 42 |
'Property operator expected value to be one of ["-"] but got "~"', |
| 43 |
); |
| 44 |
|
| 45 |
expect(() => { |
| 46 |
t.tsLiteralType(t.unaryExpression("void", t.numericLiteral(1))); |
| 47 |
}).toThrow( |
| 48 |
'Property operator expected value to be one of ["-"] but got "void"', |
| 49 |
); |
| 50 |
}); |
| 51 |
}); |
| 52 |
}); |