Declare "sut" (= subject under test) variable in all tests.
This commit is contained in:
parent
5841195cda
commit
bdf15d277e
10 changed files with 102 additions and 36 deletions
|
@ -1,16 +1,23 @@
|
||||||
import {Base64Decoder} from './base64-decoder';
|
import {Base64Decoder} from './base64-decoder';
|
||||||
|
|
||||||
describe('Base64Decoder', () => {
|
describe('Base64Decoder', () => {
|
||||||
|
let sut: Base64Decoder;
|
||||||
|
|
||||||
|
beforeEach(() => sut = new Base64Decoder());
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should create an instance', () => {
|
||||||
expect(new Base64Decoder()).toBeTruthy();
|
expect(sut).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have the id "base64decode"', () => {
|
it('should have the id "base64decode"', () => {
|
||||||
expect(new Base64Decoder().getId()).toEqual('base64decode');
|
expect(sut.getId()).toEqual('base64decode');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should decode "SGVsbG8sIFdvcmxkIQ==" to "Hello, World!"', () => {
|
it('should decode "SGVsbG8sIFdvcmxkIQ==" to "Hello, World!"', () => {
|
||||||
expect(new Base64Decoder().convert('SGVsbG8sIFdvcmxkIQ==')).toEqual('Hello, World!');
|
expect(sut.convert('SGVsbG8sIFdvcmxkIQ==')).toEqual('Hello, World!');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should raise an exception on invalid input', () => {
|
it('should raise an exception on invalid input', () => {
|
||||||
expect(() => new Base64Decoder().convert('foo bar.')).toThrowError('Could not decode base64 string. Maybe corrupt input?');
|
expect(() => sut.convert('foo bar.')).toThrowError('Could not decode base64 string. Maybe corrupt input?');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
import {Base64Encoder} from './base64-encoder';
|
import {Base64Encoder} from './base64-encoder';
|
||||||
|
|
||||||
describe('Base64Encoder', () => {
|
describe('Base64Encoder', () => {
|
||||||
|
let sut: Base64Encoder;
|
||||||
|
|
||||||
|
beforeEach(() => sut = new Base64Encoder());
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should create an instance', () => {
|
||||||
expect(new Base64Encoder()).toBeTruthy();
|
expect(sut).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have the id "base64encode"', () => {
|
it('should have the id "base64encode"', () => {
|
||||||
expect(new Base64Encoder().getId()).toEqual('base64encode');
|
expect(sut.getId()).toEqual('base64encode');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should encode "Oh, guete Tag!" to "T2gsIGd1ZXRlIFRhZyE="', () => {
|
it('should encode "Oh, guete Tag!" to "T2gsIGd1ZXRlIFRhZyE="', () => {
|
||||||
expect(new Base64Encoder().convert('Oh, guete Tag!')).toEqual('T2gsIGd1ZXRlIFRhZyE=');
|
expect(sut.convert('Oh, guete Tag!')).toEqual('T2gsIGd1ZXRlIFRhZyE=');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should raise an exception on invalid input', () => {
|
it('should raise an exception on invalid input', () => {
|
||||||
expect(() => new Base64Encoder().convert('€')).toThrowError(/Looks like you've got a character outside of the Latin1 range there./);
|
expect(() => sut.convert('€')).toThrowError(/Looks like you've got a character outside of the Latin1 range there./);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
import {BinToDecConverter} from './bin-to-dec-converter';
|
import {BinToDecConverter} from './bin-to-dec-converter';
|
||||||
|
|
||||||
describe('BinToDecConverter', () => {
|
describe('BinToDecConverter', () => {
|
||||||
|
let sut: BinToDecConverter;
|
||||||
|
|
||||||
|
beforeEach(() => sut = new BinToDecConverter());
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should create an instance', () => {
|
||||||
expect(new BinToDecConverter()).toBeTruthy();
|
expect(sut).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have the id "bintodec"', () => {
|
it('should have the id "bintodec"', () => {
|
||||||
expect(new BinToDecConverter().getId()).toEqual('bintodec');
|
expect(sut.getId()).toEqual('bintodec');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert "11011" to "27"', () => {
|
it('should convert "11011" to "27"', () => {
|
||||||
expect(new BinToDecConverter().convert('11011')).toEqual('27');
|
expect(sut.convert('11011')).toEqual('27');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should raise an exception on invalid input', () => {
|
it('should raise an exception on invalid input', () => {
|
||||||
expect(() => new BinToDecConverter().convert('1foo bar')).toThrowError('The input seems not to be a valid binary number.');
|
expect(() => sut.convert('1foo bar')).toThrowError('The input seems not to be a valid binary number.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
import {DecToBinConverter} from './dec-to-bin-converter';
|
import {DecToBinConverter} from './dec-to-bin-converter';
|
||||||
|
|
||||||
describe('DecToBinConverter', () => {
|
describe('DecToBinConverter', () => {
|
||||||
|
let sut: DecToBinConverter;
|
||||||
|
|
||||||
|
beforeEach(() => sut = new DecToBinConverter());
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should create an instance', () => {
|
||||||
expect(new DecToBinConverter()).toBeTruthy();
|
expect(sut).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have the id "dectobin"', () => {
|
it('should have the id "dectobin"', () => {
|
||||||
expect(new DecToBinConverter().getId()).toEqual('dectobin');
|
expect(sut.getId()).toEqual('dectobin');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert "22" to "10110"', () => {
|
it('should convert "22" to "10110"', () => {
|
||||||
expect(new DecToBinConverter().convert('22')).toEqual('10110');
|
expect(sut.convert('22')).toEqual('10110');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should raise an exception on invalid input', () => {
|
it('should raise an exception on invalid input', () => {
|
||||||
expect(() => new DecToBinConverter().convert('foo bar')).toThrowError('The input seems not to be a valid integer.');
|
expect(() => sut.convert('foo bar')).toThrowError('The input seems not to be a valid integer.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
import {DecToHexConverter} from './dec-to-hex-converter';
|
import {DecToHexConverter} from './dec-to-hex-converter';
|
||||||
|
|
||||||
describe('DecToHexConverter', () => {
|
describe('DecToHexConverter', () => {
|
||||||
|
let sut: DecToHexConverter;
|
||||||
|
|
||||||
|
beforeEach(() => sut = new DecToHexConverter());
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should create an instance', () => {
|
||||||
expect(new DecToHexConverter()).toBeTruthy();
|
expect(sut).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have the id "dectohex"', () => {
|
it('should have the id "dectohex"', () => {
|
||||||
expect(new DecToHexConverter().getId()).toEqual('dectohex');
|
expect(sut.getId()).toEqual('dectohex');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert "22" to "16"', () => {
|
it('should convert "22" to "16"', () => {
|
||||||
expect(new DecToHexConverter().convert('22')).toEqual('16');
|
expect(sut.convert('22')).toEqual('16');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should raise an exception on invalid input', () => {
|
it('should raise an exception on invalid input', () => {
|
||||||
expect(() => new DecToHexConverter().convert('foo bar')).toThrowError('The input seems not to be a valid integer.');
|
expect(() => sut.convert('foo bar')).toThrowError('The input seems not to be a valid integer.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
import {HexToDecConverter} from './hex-to-dec-converter';
|
import {HexToDecConverter} from './hex-to-dec-converter';
|
||||||
|
|
||||||
describe('HexToDecConverter', () => {
|
describe('HexToDecConverter', () => {
|
||||||
|
let sut: HexToDecConverter;
|
||||||
|
|
||||||
|
beforeEach(() => sut = new HexToDecConverter());
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should create an instance', () => {
|
||||||
expect(new HexToDecConverter()).toBeTruthy();
|
expect(sut).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have the id "hextodec"', () => {
|
it('should have the id "hextodec"', () => {
|
||||||
expect(new HexToDecConverter().getId()).toEqual('hextodec');
|
expect(sut.getId()).toEqual('hextodec');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert "ab" to "171"', () => {
|
it('should convert "ab" to "171"', () => {
|
||||||
expect(new HexToDecConverter().convert('ab')).toEqual('171');
|
expect(sut.convert('ab')).toEqual('171');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should raise an exception on invalid input', () => {
|
it('should raise an exception on invalid input', () => {
|
||||||
expect(() => new HexToDecConverter().convert('foo bar')).toThrowError('The input seems not to be a valid hexadecimal number.');
|
expect(() => sut.convert('foo bar')).toThrowError('The input seems not to be a valid hexadecimal number.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
import {HTMLEntitiesDecoder} from './htmlentities-decoder';
|
import {HTMLEntitiesDecoder} from './htmlentities-decoder';
|
||||||
|
|
||||||
describe('HTMLEntitiesDecoder', () => {
|
describe('HTMLEntitiesDecoder', () => {
|
||||||
|
let sut: HTMLEntitiesDecoder;
|
||||||
|
|
||||||
|
beforeEach(() => sut = new HTMLEntitiesDecoder());
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should create an instance', () => {
|
||||||
expect(new HTMLEntitiesDecoder()).toBeTruthy();
|
expect(sut).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have the id "decodehtmlentities"', () => {
|
it('should have the id "decodehtmlentities"', () => {
|
||||||
expect(new HTMLEntitiesDecoder().getId()).toEqual('decodehtmlentities');
|
expect(sut.getId()).toEqual('decodehtmlentities');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should decode "<span>"Hi" & "Lo"</span>" to "<span>"Hi" & "Lo"</span>"', () => {
|
it('should decode "<span>"Hi" & "Lo"</span>" to "<span>"Hi" & "Lo"</span>"', () => {
|
||||||
expect(new HTMLEntitiesDecoder().convert('<span>"Hi" & "Lo"</span>'))
|
expect(sut.convert('<span>"Hi" & "Lo"</span>'))
|
||||||
.toEqual('<span>"Hi" & "Lo"</span>');
|
.toEqual('<span>"Hi" & "Lo"</span>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
import {HTMLEntitiesEncoder} from './htmlentities-encoder';
|
import {HTMLEntitiesEncoder} from './htmlentities-encoder';
|
||||||
|
|
||||||
describe('HTMLEntitiesEncoder', () => {
|
describe('HTMLEntitiesEncoder', () => {
|
||||||
|
let sut: HTMLEntitiesEncoder;
|
||||||
|
|
||||||
|
beforeEach(() => sut = new HTMLEntitiesEncoder());
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should create an instance', () => {
|
||||||
expect(new HTMLEntitiesEncoder()).toBeTruthy();
|
expect(sut).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have the id "encodehtmlentities"', () => {
|
it('should have the id "encodehtmlentities"', () => {
|
||||||
expect(new HTMLEntitiesEncoder().getId()).toEqual('encodehtmlentities');
|
expect(sut.getId()).toEqual('encodehtmlentities');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should encode "<span>"Hi" & "Lo"</span>" to "<span>"Hi" & "Lo"</span>"', () => {
|
it('should encode "<span>"Hi" & "Lo"</span>" to "<span>"Hi" & "Lo"</span>"', () => {
|
||||||
expect(new HTMLEntitiesEncoder().convert('<span>"Hi" & "Lo"</span>'))
|
expect(sut.convert('<span>"Hi" & "Lo"</span>'))
|
||||||
.toEqual('<span>"Hi" & "Lo"</span>');
|
.toEqual('<span>"Hi" & "Lo"</span>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,23 +4,29 @@ import createSpyObj = jasmine.createSpyObj;
|
||||||
import Spy = jasmine.Spy;
|
import Spy = jasmine.Spy;
|
||||||
|
|
||||||
describe('PunycodeDecoder', () => {
|
describe('PunycodeDecoder', () => {
|
||||||
|
let sut: PunycodeDecoder;
|
||||||
let nativeWrapperSpy: Partial<NativeLibraryWrapperService>;
|
let nativeWrapperSpy: Partial<NativeLibraryWrapperService>;
|
||||||
let decodeSpy: Spy;
|
let decodeSpy: Spy;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
nativeWrapperSpy = {punycode: createSpyObj(['decode'])};
|
nativeWrapperSpy = {punycode: createSpyObj(['decode'])};
|
||||||
decodeSpy = nativeWrapperSpy.punycode.decode as Spy;
|
decodeSpy = nativeWrapperSpy.punycode.decode as Spy;
|
||||||
|
sut = new PunycodeDecoder((nativeWrapperSpy as NativeLibraryWrapperService));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should create an instance', () => {
|
||||||
expect(new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService)).toBeTruthy();
|
expect(sut).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have the id "decodepunycode"', () => {
|
it('should have the id "decodepunycode"', () => {
|
||||||
expect(new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService).getId()).toEqual('decodepunycode');
|
expect(sut.getId()).toEqual('decodepunycode');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call through to the native punycode decoder', () => {
|
it('should call through to the native punycode decoder', () => {
|
||||||
const testInput = 'My input';
|
const testInput = 'My input';
|
||||||
const expectedOutput = 'It worked';
|
const expectedOutput = 'It worked';
|
||||||
decodeSpy.and.returnValue(expectedOutput);
|
decodeSpy.and.returnValue(expectedOutput);
|
||||||
const result: string = new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService).convert(testInput);
|
const result: string = sut.convert(testInput);
|
||||||
expect(result).toEqual(expectedOutput);
|
expect(result).toEqual(expectedOutput);
|
||||||
expect(decodeSpy).toHaveBeenCalledWith(testInput);
|
expect(decodeSpy).toHaveBeenCalledWith(testInput);
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,23 +4,29 @@ import createSpyObj = jasmine.createSpyObj;
|
||||||
import Spy = jasmine.Spy;
|
import Spy = jasmine.Spy;
|
||||||
|
|
||||||
describe('PunycodeEncoder', () => {
|
describe('PunycodeEncoder', () => {
|
||||||
|
let sut: PunycodeEncoder;
|
||||||
let nativeWrapperSpy: Partial<NativeLibraryWrapperService>;
|
let nativeWrapperSpy: Partial<NativeLibraryWrapperService>;
|
||||||
let encodeSpy: Spy;
|
let encodeSpy: Spy;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
nativeWrapperSpy = {punycode: createSpyObj(['encode'])};
|
nativeWrapperSpy = {punycode: createSpyObj(['encode'])};
|
||||||
encodeSpy = nativeWrapperSpy.punycode.encode as Spy;
|
encodeSpy = nativeWrapperSpy.punycode.encode as Spy;
|
||||||
|
sut = new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should create an instance', () => {
|
||||||
expect(new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService)).toBeTruthy();
|
expect(sut).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have the id "encodepunycode"', () => {
|
it('should have the id "encodepunycode"', () => {
|
||||||
expect(new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService).getId()).toEqual('encodepunycode');
|
expect(sut.getId()).toEqual('encodepunycode');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call through to the native punycode encoder', () => {
|
it('should call through to the native punycode encoder', () => {
|
||||||
const testInput = 'My input';
|
const testInput = 'My input';
|
||||||
const expectedOutput = 'It worked';
|
const expectedOutput = 'It worked';
|
||||||
encodeSpy.and.returnValue(expectedOutput);
|
encodeSpy.and.returnValue(expectedOutput);
|
||||||
const result: string = new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService).convert(testInput);
|
const result: string = sut.convert(testInput);
|
||||||
expect(result).toEqual(expectedOutput);
|
expect(result).toEqual(expectedOutput);
|
||||||
expect(encodeSpy).toHaveBeenCalledWith(testInput);
|
expect(encodeSpy).toHaveBeenCalledWith(testInput);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue