Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 1 | import {SafePipe} from "./safe.pipe"; |
| 2 | import {DomSanitizer} from "@angular/platform-browser"; |
| 3 | import {getTestBed, TestBed} from "@angular/core/testing"; |
| 4 | |
| 5 | |
| 6 | describe('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 | }); |