-
Notifications
You must be signed in to change notification settings - Fork 396
/
index.spec.js
41 lines (31 loc) · 1.16 KB
/
index.spec.js
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
import { createElement } from 'lwc';
import Xlink from 'x/xlink';
const originalSanitizeAttribute = LWC.sanitizeAttribute;
afterEach(() => {
// Reset original sanitizer after each test.
LWC.sanitizeAttribute = originalSanitizeAttribute;
});
it('uses the original passthrough sanitizer when not overridden', () => {
const elm = createElement('x-link', { is: Xlink });
document.body.appendChild(elm);
const use = elm.shadowRoot.querySelector('use');
expect(use.getAttribute('xlink:href')).toBe('/foo');
});
it('receives the right parameters', () => {
spyOn(LWC, 'sanitizeAttribute');
const elm = createElement('x-link', { is: Xlink });
document.body.appendChild(elm);
expect(LWC.sanitizeAttribute).toHaveBeenCalledWith(
'use',
'http://www.w3.org/2000/svg',
'xlink:href',
'/foo'
);
});
it('replace the original attribute value with the returned value', () => {
LWC.sanitizeAttribute = () => '/bar';
const elm = createElement('x-link', { is: Xlink });
document.body.appendChild(elm);
const use = elm.shadowRoot.querySelector('use');
expect(use.getAttribute('xlink:href')).toBe('/bar');
});