summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/pipes/safe/safe.pipe.spec.ts
blob: f0471731eb208425a3341830d87218607918d0b5 (plain)
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
57
58
59
60
import {SafePipe} from "./safe.pipe";
import {DomSanitizer} from "@angular/platform-browser";
import {getTestBed, TestBed} from "@angular/core/testing";


describe('Safe pipe', () => {

  let injector;
  let pipe: SafePipe;
  let sanitizer: DomSanitizer;

  beforeAll(done => (async () => {
    TestBed.configureTestingModule({
      providers: [SafePipe]
    });
    await TestBed.compileComponents();

    injector = getTestBed();
    sanitizer = injector.get(DomSanitizer);
    pipe = injector.get(SafePipe);

  })().then(done).catch(done.fail));

  test('safe pipe should return Safe object', () => {
    let options = [
      {
        value: 'value',
        type: 'html',
        func: 'bypassSecurityTrustHtml'
      },
      {
        value: 'value',
        type: 'style',
        func: 'bypassSecurityTrustStyle'
      },
      {
        value: 'value',
        type: 'script',
        func: 'bypassSecurityTrustScript'
      },
      {
        value: 'value',
        type: 'url',
        func: 'bypassSecurityTrustUrl'
      },
      {
        value: 'value',
        type: 'resourceUrl',
        func: 'bypassSecurityTrustResourceUrl'
      }
    ];

    for (let option of options) {
      jest.spyOn(sanitizer, <any>option.func);
      pipe.transform(option.value, option.type);
      expect(sanitizer[option.func]).toHaveBeenCalledWith(option.value);
    }
  });

});