converter/src/app/converter/utf8-decoder.spec.ts

38 lines
1.1 KiB
TypeScript

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<NativeLibraryWrapperService>;
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 a display name', () => {
expect(sut.getDisplayname()).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);
});
});