-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathhelper.spec.js
More file actions
56 lines (53 loc) · 1.44 KB
/
helper.spec.js
File metadata and controls
56 lines (53 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { camelize, console, insertNodeAt } from "@/util/helper";
describe("camelize", () => {
test.each([
["MyProp", "MyProp"],
["MyProp", "MyProp"],
["kebab-case", "kebabCase"],
["multi-hyphen-string", "multiHyphenString"],
["drag-class", "dragClass"],
["test-", "test-"]
])(
"transform %s into %s",
(value, expected) =>{
const actual = camelize(value);
expect(actual).toEqual(expected);
}
)
});
describe("console", () => {
test.each([
["log"],
["warn"],
["error"],
["info"],
])(
"has %s function",
(key) =>{
const actual = console[key];
expect(typeof actual).toEqual("function");
}
)
});
describe('insertNodeAt', () => {
const node = document.createElement('div');
const nextSibling = document.createElement('div');
const child = { nextSibling };
const mockInsertBefore = jest.fn();
const fatherNode = {
insertBefore: mockInsertBefore,
children: [child]
}
test('Inserts node at 0 position', () => {
insertNodeAt(fatherNode, node, 0);
expect(mockInsertBefore).toHaveBeenCalledWith(node, child);
})
test('Inserts node at 1 position', () => {
insertNodeAt(fatherNode, node, 1);
expect(mockInsertBefore).toHaveBeenCalledWith(node, nextSibling);
})
test("Inserts node at the end of node's child nodes", () => {
insertNodeAt(fatherNode, node, 2);
expect(mockInsertBefore).toHaveBeenCalledWith(node, undefined);
})
});