blob: f0471731eb208425a3341830d87218607918d0b5 [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {SafePipe} from "./safe.pipe";
2import {DomSanitizer} from "@angular/platform-browser";
3import {getTestBed, TestBed} from "@angular/core/testing";
4
5
6describe('Safe pipe', () => {
7
8 let injector;
9 let pipe: SafePipe;
10 let sanitizer: DomSanitizer;
11
12 beforeAll(done => (async () => {
13 TestBed.configureTestingModule({
14 providers: [SafePipe]
15 });
16 await TestBed.compileComponents();
17
18 injector = getTestBed();
19 sanitizer = injector.get(DomSanitizer);
20 pipe = injector.get(SafePipe);
21
22 })().then(done).catch(done.fail));
23
24 test('safe pipe should return Safe object', () => {
25 let options = [
26 {
27 value: 'value',
28 type: 'html',
29 func: 'bypassSecurityTrustHtml'
30 },
31 {
32 value: 'value',
33 type: 'style',
34 func: 'bypassSecurityTrustStyle'
35 },
36 {
37 value: 'value',
38 type: 'script',
39 func: 'bypassSecurityTrustScript'
40 },
41 {
42 value: 'value',
43 type: 'url',
44 func: 'bypassSecurityTrustUrl'
45 },
46 {
47 value: 'value',
48 type: 'resourceUrl',
49 func: 'bypassSecurityTrustResourceUrl'
50 }
51 ];
52
53 for (let option of options) {
54 jest.spyOn(sanitizer, <any>option.func);
55 pipe.transform(option.value, option.type);
56 expect(sanitizer[option.func]).toHaveBeenCalledWith(option.value);
57 }
58 });
59
60});