import {PunycodeDecoder} from './punycode-decoder'; import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; import createSpyObj = jasmine.createSpyObj; import Spy = jasmine.Spy; describe('PunycodeDecoder', () => { let sut: PunycodeDecoder; let nativeWrapperSpy: Partial; let decodeSpy: Spy; beforeEach(() => { nativeWrapperSpy = {punycode: createSpyObj(['decode'])}; decodeSpy = nativeWrapperSpy.punycode.decode as Spy; sut = new PunycodeDecoder((nativeWrapperSpy as NativeLibraryWrapperService)); }); it('should create an instance', () => { expect(sut).toBeTruthy(); }); it('should have the id "decodepunycode"', () => { expect(sut.getId()).toEqual('decodepunycode'); }); it('should call through to the native punycode 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); }); });