-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathindex.spec.js
More file actions
34 lines (31 loc) · 1.35 KB
/
index.spec.js
File metadata and controls
34 lines (31 loc) · 1.35 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
export default {
props: {},
snapshot(target) {
const first = target.shadowRoot.querySelector('.first');
const second = target.shadowRoot.querySelector('.second');
return {
first,
second,
};
},
advancedTest(target, { Component, hydrateComponent, consoleSpy, container, selector }) {
const snapshotBeforeHydration = this.snapshot(target);
hydrateComponent(target, Component, this.props);
const hydratedTarget = container.querySelector(selector);
const snapshotAfterHydration = this.snapshot(hydratedTarget);
for (const snapshotKey of Object.keys(snapshotBeforeHydration)) {
expect(snapshotBeforeHydration[snapshotKey])
.withContext(
`${snapshotKey} should be the same DOM element both before and after hydration`
)
.toBe(snapshotAfterHydration[snapshotKey]);
expect(snapshotBeforeHydration[snapshotKey].childNodes)
.withContext(
`${snapshotKey} should have the same number of child nodes before & after hydration`
)
.toHaveSize(snapshotAfterHydration[snapshotKey].childNodes.length);
}
expect(consoleSpy.calls.warn).toHaveSize(0);
expect(consoleSpy.calls.error).toHaveSize(0);
},
};