Skip to content

Commit 7c17532

Browse files
committed
add tests
1 parent 04c6bcc commit 7c17532

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

src/core/mockup-parser.test.js

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

0 commit comments

Comments
 (0)