Debian Codegraph @

addons/web/static/lib/hoot/tests/core/test.test.js

raw
1 /** @odoo-module */
2
3 import { describe, expect, test } from "@odoo/hoot";
4 import { parseUrl } from "../local_helpers";
5
6 import { Suite } from "../../core/suite";
7 import { Test } from "../../core/test";
8
9 function disableHighlighting() {
10 if (!window.Prism) {
11 return () => {};
12 }
13 const { highlight } = window.Prism;
14 window.Prism.highlight = (text) => text;
15
16 return function restoreHighlighting() {
17 window.Prism.highlight = highlight;
18 };
19 }
20
21 describe(parseUrl(import.meta.url), () => {
22 test("should have a hashed id", () => {
23 expect(new Test(null, "a test", {}).id).toMatch(/^\w{8}$/);
24 });
25
26 test("should describe its path in its name", () => {
27 const a = new Suite(null, "a", {});
28 const b = new Suite(a, "b", {});
29 const t1 = new Test(null, "t1", {});
30 const t2 = new Test(a, "t2", {});
31 const t3 = new Test(b, "t3", {});
32
33 expect(t1.fullName).toBe("t1");
34 expect(t2.fullName).toBe("a/t2");
35 expect(t3.fullName).toBe("a/b/t3");
36 });
37
38 test("run is async and lazily formatted", () => {
39 const restoreHighlighting = disableHighlighting();
40
41 const testName = "some test";
42 const t = new Test(null, testName, {});
43 const runFn = () => {
44 // Synchronous
45 expect(1).toBe(1);
46 };
47
48 expect(t.run).toBe(null);
49 expect(t.runFnString).toBe("");
50 expect(t.formatted).toBe(false);
51
52 t.setRunFn(runFn);
53
54 expect(t.run()).toBeInstanceOf(Promise);
55 expect(t.runFnString).toBe(runFn.toString());
56 expect(t.formatted).toBe(false);
57
58 expect(String(t.code)).toBe(
59 `
60 test("${testName}", () => {
61 // Synchronous
62 expect(1).toBe(1);
63 });
64 `.trim()
65 );
66 expect(t.formatted).toBe(true);
67
68 restoreHighlighting();
69 });
70 });