| 1 |
import * as t from "../../../lib/index.js"; |
| 2 |
|
| 3 |
describe("builders", function () { |
| 4 |
describe("es2015", function () { |
| 5 |
describe("templateElement", function () { |
| 6 |
it("should validate", function () { |
| 7 |
expect( |
| 8 |
t.templateElement({ raw: "foo", cooked: "foo" }), |
| 9 |
).toMatchSnapshot(); |
| 10 |
|
| 11 |
expect(t.templateElement({ raw: "foo" })).toMatchSnapshot(); |
| 12 |
|
| 13 |
expect(() => |
| 14 |
t.templateElement({ raw: 1 }), |
| 15 |
).toThrowErrorMatchingSnapshot(); |
| 16 |
|
| 17 |
expect(() => |
| 18 |
t.templateElement({ raw: "foo", cooked: 1 }), |
| 19 |
).toThrowErrorMatchingSnapshot(); |
| 20 |
|
| 21 |
expect(() => t.templateElement("foo")).toThrowErrorMatchingSnapshot(); |
| 22 |
|
| 23 |
expect(t.templateElement({ raw: "\\u" })).toMatchSnapshot(); |
| 24 |
|
| 25 |
expect(t.templateElement({ raw: "\\x42" })).toMatchSnapshot(); |
| 26 |
|
| 27 |
expect( |
| 28 |
t.templateElement({ raw: "\\x42", cooked: "123" }), |
| 29 |
).toMatchSnapshot(); |
| 30 |
|
| 31 |
expect(() => |
| 32 |
t.templateElement({ raw: "`" }), |
| 33 |
).toThrowErrorMatchingSnapshot(); |
| 34 |
|
| 35 |
expect(() => |
| 36 |
t.templateElement({ raw: "${" }), |
| 37 |
).toThrowErrorMatchingSnapshot(); |
| 38 |
}); |
| 39 |
}); |
| 40 |
describe("templateLiteral", function () { |
| 41 |
it("should validate", function () { |
| 42 |
const foo = t.templateElement({ raw: "foo" }); |
| 43 |
const bar = t.templateElement({ raw: "bar" }); |
| 44 |
|
| 45 |
const baz = t.stringLiteral("baz"); |
| 46 |
const qux = t.stringLiteral("qux"); |
| 47 |
|
| 48 |
expect(t.templateLiteral([foo], [])).toMatchSnapshot(); |
| 49 |
|
| 50 |
expect(t.templateLiteral([foo, bar], [baz])).toMatchSnapshot(); |
| 51 |
|
| 52 |
expect(() => |
| 53 |
t.templateLiteral([foo, bar], [baz, qux]), |
| 54 |
).toThrowErrorMatchingSnapshot(); |
| 55 |
|
| 56 |
expect(() => |
| 57 |
t.templateLiteral([foo, bar], []), |
| 58 |
).toThrowErrorMatchingSnapshot(); |
| 59 |
|
| 60 |
expect(() => |
| 61 |
t.templateLiteral({}, [baz]), |
| 62 |
).toThrowErrorMatchingSnapshot(); |
| 63 |
|
| 64 |
expect(() => |
| 65 |
t.templateLiteral([foo, bar]), |
| 66 |
).toThrowErrorMatchingSnapshot(); |
| 67 |
}); |
| 68 |
}); |
| 69 |
}); |
| 70 |
}); |