import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; import {UTF8Encoder} from './utf8-encoder'; import createSpyObj = jasmine.createSpyObj; import Spy = jasmine.Spy; describe('UTF8Encoder', () => { let sut: UTF8Encoder; let nativeWrapperSpy: Partial; let encodeSpy: Spy; beforeEach(() => { nativeWrapperSpy = {utf8: createSpyObj(['encode'])}; encodeSpy = nativeWrapperSpy.utf8.encode as Spy; sut = new UTF8Encoder(nativeWrapperSpy as NativeLibraryWrapperService); }); it('should create an instance', () => { expect(sut).toBeTruthy(); }); it('should have a display name', () => { expect(sut.getDisplayname()).toBeTruthy(); }); it('should have the id "encodeutf8"', () => { expect(sut.getId()).toEqual('encodeutf8'); }); it('should call through to the native UTF-8 encoder', () => { const testInput = 'My input'; const expectedOutput = 'It worked'; encodeSpy.and.returnValue(expectedOutput); const result: string = sut.convert(testInput); expect(result).toEqual(expectedOutput); expect(encodeSpy).toHaveBeenCalledWith(testInput); }); });