|
1 | | -import $ from "jquery"; |
2 | 1 | import mockupParser from "./mockup-parser"; |
3 | 2 |
|
4 | 3 | describe("The mockup-parser", function () { |
5 | 4 | it("parses the data attribute of a single node", function () { |
6 | | - const $el = $(` |
7 | | - <span data-pat-testpattern="option1: value1; option2: value2"> |
8 | | - mockup parser test |
9 | | - </span>`); |
10 | | - const options = mockupParser.getOptions($el, "testpattern"); |
| 5 | + const el = document.createElement("div"); |
| 6 | + el.setAttribute("data-pat-testpattern", "option1: value1; option2: value2"); |
| 7 | + |
| 8 | + const options = mockupParser.getOptions(el, "testpattern"); |
| 9 | + |
11 | 10 | expect(options.option1).toBe("value1"); |
12 | 11 | expect(options.option2).toBe("value2"); |
13 | 12 | }); |
| 13 | + |
14 | 14 | it("parses the data attribute of nested nodes", function () { |
15 | | - const $el = $(` |
16 | | - <div data-pat-testpattern="parentOption1: value1; parentOption2: value2"> |
17 | | - <span class="pat-testpattern" data-pat-testpattern="option1: subvalue1; option2: subvalue2"> |
18 | | - nested mockup parser test |
19 | | - </span> |
20 | | - </div>`); |
21 | | - const options = mockupParser.getOptions($(".pat-testpattern", $el), "testpattern"); |
| 15 | + const el = document.createElement("div"); |
| 16 | + el.setAttribute( |
| 17 | + "data-pat-testpattern", |
| 18 | + "parentOption1: value1; parentOption2: value2" |
| 19 | + ); |
| 20 | + const el2 = document.createElement("span"); |
| 21 | + el2.setAttribute( |
| 22 | + "data-pat-testpattern", |
| 23 | + "option1: subvalue1; option2: subvalue2" |
| 24 | + ); |
| 25 | + el.appendChild(el2); |
| 26 | + |
| 27 | + const options = mockupParser.getOptions(el2, "testpattern"); |
| 28 | + |
22 | 29 | expect(options.parentOption1).toBe("value1"); |
23 | 30 | expect(options.parentOption2).toBe("value2"); |
24 | 31 | expect(options.option1).toBe("subvalue1"); |
25 | 32 | expect(options.option2).toBe("subvalue2"); |
26 | 33 | }); |
| 34 | + |
27 | 35 | it("parses the data attribute of a single node and preserves injected options", function () { |
28 | | - const $el = $(` |
29 | | - <span data-pat-testpattern="option1: value1; option2: value2"> |
30 | | - mockup parser test |
31 | | - </span> |
32 | | - `); |
33 | | - const options = mockupParser.getOptions($el, "testpattern", { |
| 36 | + const el = document.createElement("div"); |
| 37 | + el.setAttribute("data-pat-testpattern", "option1: value1; option2: value2"); |
| 38 | + |
| 39 | + const options = mockupParser.getOptions(el, "testpattern", { |
34 | 40 | injectedOption: "injectedValue", |
35 | 41 | }); |
| 42 | + |
36 | 43 | expect(options.option1).toBe("value1"); |
37 | 44 | expect(options.option2).toBe("value2"); |
38 | 45 | expect(options.injectedOption).toBe("injectedValue"); |
|
0 commit comments