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