2020-07-04 10:09:48 -07:00
|
|
|
test("basic functionality", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(String.raw).toHaveLength(1);
|
2020-05-06 17:49:48 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
let str = String.raw`foo\nbar`;
|
|
|
|
|
expect(str).toHaveLength(8);
|
|
|
|
|
expect(str).toBe("foo\\nbar");
|
2020-05-06 17:49:48 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
str = String.raw`foo ${1 + 9}\nbar${"hf!"}`;
|
|
|
|
|
expect(str).toBe("foo 10\\nbarhf!");
|
2020-05-06 17:49:48 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
str = String.raw`${10}${20}${30}`;
|
|
|
|
|
expect(str).toBe("102030");
|
2020-05-06 17:49:48 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
str = String.raw({ raw: ["foo ", "\\nbar"] }, 10, "hf!");
|
|
|
|
|
expect(str).toBe("foo 10\\nbar");
|
2020-05-06 17:49:48 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
str = String.raw({ raw: ["foo ", "\\nbar"] });
|
|
|
|
|
expect(str).toBe("foo \\nbar");
|
2020-05-06 17:49:48 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
str = String.raw({ raw: [] }, 10, "hf!");
|
|
|
|
|
expect(str).toBe("");
|
2020-05-06 17:49:48 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
str = String.raw({ raw: 1 });
|
|
|
|
|
expect(str).toBe("");
|
2020-07-04 10:09:48 -07:00
|
|
|
});
|
2020-05-06 17:49:48 -07:00
|
|
|
|
2020-07-04 10:09:48 -07:00
|
|
|
test("passing object with no 'raw' property", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(() => {
|
|
|
|
|
String.raw({});
|
|
|
|
|
}).toThrowWithMessage(TypeError, "Cannot convert property 'raw' to object from undefined");
|
2020-07-04 10:09:48 -07:00
|
|
|
});
|