From 7cf6b2c8607ec8e35ba2119da64ce3c7eb6aae13 Mon Sep 17 00:00:00 2001 From: masumulu28 Date: Wed, 29 Mar 2023 00:12:39 +0300 Subject: [PATCH] Test created for safe-html pipe --- .../core/src/lib/tests/safe-html.pipe.spec.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 npm/ng-packs/packages/core/src/lib/tests/safe-html.pipe.spec.ts diff --git a/npm/ng-packs/packages/core/src/lib/tests/safe-html.pipe.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/safe-html.pipe.spec.ts new file mode 100644 index 0000000000..a0c4fa6e30 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/tests/safe-html.pipe.spec.ts @@ -0,0 +1,37 @@ +import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { SafeHtmlPipe } from '../pipes'; + +describe('SafeHtmlPipe', () => { + let pipe: SafeHtmlPipe; + let spectator: SpectatorService; + const createService = createServiceFactory(SafeHtmlPipe); + + beforeEach(() => { + spectator = createService(); + pipe = spectator.service; + }); + + it('should create an instance', () => { + expect(pipe).toBeTruthy(); + }); + + it('should return empty string for non-string inputs', () => { + const inputs = [42, false, {}, []]; + for (const input of inputs) { + const result = pipe.transform(input as any); + expect(result).toBe(''); + } + }); + + it('should be equals with input after sanitized', () => { + const input = '

Hello world!

'; + const result = pipe.transform(input); + expect(result).toEqual(input); + }); + + it('should sanitize unsafe HTML content', () => { + const input = `

Click here!

`; + const result = pipe.transform(input); + expect(result).toBe(`

Click here!

`); + }); +});