Skip to content

Commit

Permalink
Improve Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
danrevah committed Mar 13, 2017
1 parent 1cd3034 commit e80146e
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/app/pipes/array/every.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('EveryPipe', () => {
});

it('should check if every elements of the array fits the predicate', () => {
expect(pipe.transform(42, isNumber)).toBeFalsy();
expect(pipe.transform([1, 2, 3, 4], isNumber)).toBeTruthy();
expect(pipe.transform([1, 2, 3, 'a'], isNumber)).toBeFalsy();
expect(pipe.transform([1, 2, 3, 4], isUndefined)).toBeFalsy();
Expand Down
4 changes: 2 additions & 2 deletions src/app/pipes/array/every.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {PipeTransform, Pipe} from '@angular/core';
@Pipe({name: 'every'})
export class EveryPipe implements PipeTransform {

transform(input: any[], predicate: (value: any, index: number, array: any[]) => boolean): boolean|any[] {
return Array.isArray(input) ? input.every(predicate) : input;
transform(input: any, predicate: (value: any, index: number, array: any[]) => boolean): boolean|any[] {
return Array.isArray(input) ? input.every(predicate) : false;
}
}
5 changes: 5 additions & 0 deletions src/app/pipes/array/initial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ describe('InitialPipe', () => {
pipe = new InitialPipe();
});

it('should return value if not array', () => {
expect(pipe.transform(42)).toEqual(42);
expect(pipe.transform(false)).toEqual(false);
});

it('should check that nothing happens if there are no parameters', () => {
let arr = [1, 2, 3];
let result = pipe.transform(arr);
Expand Down
5 changes: 5 additions & 0 deletions src/app/pipes/array/unique.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ describe('DiffPipe', () => {
pipe = new UniquePipe();
});

it('should return value if not array', () => {
expect(pipe.transform(42)).toEqual(42);
expect(pipe.transform(false)).toEqual(false);
});

it('should keep the array the same way if it doesn\'t have any duplicate elements', () => {
expect(pipe.transform([1, 2, 3])).toEqual([1, 2, 3]);
expect(pipe.transform([])).toEqual([]);
Expand Down
1 change: 1 addition & 0 deletions src/app/pipes/math/max.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('MaxPipe', () => {
});

it('should return max element from array', () => {
expect(pipe.transform(1)).toEqual(1);
expect(pipe.transform([1, 2, 3])).toEqual(3);
expect(pipe.transform([5, 4, 3, 2, 1, 2, 3, 4, 5])).toEqual(5);
expect(pipe.transform([5, 4, 3, 2, 1, 2, 3, 4, -5, 19])).toEqual(19);
Expand Down
2 changes: 1 addition & 1 deletion src/app/pipes/math/max.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {PipeTransform, Pipe} from '@angular/core';
@Pipe({name: 'max'})
export class MaxPipe implements PipeTransform {

transform(arr: number[]): number|number[] {
transform(arr: any): number|number[] {
return Array.isArray(arr)
? Math.max(...arr)
: arr;
Expand Down
1 change: 1 addition & 0 deletions src/app/pipes/math/min.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('MinPipe', () => {
});

it('should return min element from array', () => {
expect(pipe.transform(42)).toEqual(42);
expect(pipe.transform([1, 2, 3])).toEqual(1);
expect(pipe.transform([5, 4, 3, 2, 1, 2, 3, 4, 5])).toEqual(1);
expect(pipe.transform([5, 4, 3, 2, 1, 2, 3, 4, -5])).toEqual(-5);
Expand Down
2 changes: 1 addition & 1 deletion src/app/pipes/math/min.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {PipeTransform, Pipe} from '@angular/core';
@Pipe({name: 'min'})
export class MinPipe implements PipeTransform {

transform(arr: number[]): number|number[] {
transform(arr: any): number|number[] {
return Array.isArray(arr)
? Math.min(...arr)
: arr;
Expand Down
5 changes: 5 additions & 0 deletions src/app/pipes/math/pow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ describe('PowerPipe', () => {
pipe = new PowerPipe();
});

it('should return value if not a number', () => {
expect(pipe.transform({a: 1})).toEqual({a: 1});
expect(pipe.transform(NaN)).toEqual(NaN);
});

it('should return power of a given number', () => {
expect(pipe.transform(3)).toEqual(9);
expect(pipe.transform(3, 3)).toEqual(27);
Expand Down
2 changes: 1 addition & 1 deletion src/app/pipes/math/pow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {PipeTransform, Pipe} from '@angular/core';
@Pipe({name: 'pow'})
export class PowerPipe implements PipeTransform {

transform(num: number, power: number = 2): number {
transform(num: any, power: number = 2): number {
return !isNaN(num)
? num ** power
: num ;
Expand Down
5 changes: 5 additions & 0 deletions src/app/pipes/math/sqrt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ describe('SqrtPipe', () => {
pipe = new SqrtPipe();
});

it('should return value if not a number', () => {
expect(pipe.transform({a: 1})).toEqual({a: 1});
expect(pipe.transform(NaN)).toEqual(NaN);
});

it('should return square of given number', () => {
expect(pipe.transform(9)).toEqual(3);
expect(pipe.transform(16)).toEqual(4);
Expand Down
2 changes: 1 addition & 1 deletion src/app/pipes/math/sqrt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {PipeTransform, Pipe} from '@angular/core';
@Pipe({name: 'sqrt'})
export class SqrtPipe implements PipeTransform {

transform(num: number): number {
transform(num: any): number {
return !isNaN(num)
? Math.sqrt(num)
: num;
Expand Down
5 changes: 5 additions & 0 deletions src/app/pipes/math/sum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ describe('SumPipe', () => {
pipe = new SumPipe();
});

it('should return value if not an array', () => {
expect(pipe.transform({a: 1})).toEqual({a: 1});
expect(pipe.transform(NaN)).toEqual(NaN);
});

it('should return sum of element', () => {
expect(pipe.transform([1, 2, 3, 4])).toEqual(10);
expect(pipe.transform([5, 4, 3, 2, 1, -2, -3, -4, -5])).toEqual(1);
Expand Down
2 changes: 1 addition & 1 deletion src/app/pipes/math/sum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {PipeTransform, Pipe} from '@angular/core';
@Pipe({name: 'sum'})
export class SumPipe implements PipeTransform {

transform(arr: number[]): number|number[] {
transform(arr: any): number|number[] {
return Array.isArray(arr)
? arr.reduce((sum, curr) => sum + curr, 0)
: arr;
Expand Down
5 changes: 3 additions & 2 deletions src/app/pipes/string/latinise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export class LatinisePipe implements PipeTransform {

transform(text: any, chars: string = '\\s'): string {
return isString(text)
? text.replace(/[^A-Za-z0-9]/g, (key: string) => (this.latinMap[key] || key))
: text;
? text.replace(/[^A-Za-z0-9]/g, (key: string) => {
return this.latinMap[key] || key;
}) : text;
}
}
5 changes: 5 additions & 0 deletions src/app/pipes/string/ucfirst.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ describe('UcFirstPipe Tests', () => {
pipe = new UcFirstPipe();
});

it('Should return value if not a string', () => {
expect(pipe.transform(42)).toEqual(42);
expect(pipe.transform(false)).toEqual(false);
});

it('Should capitalize first word in a string', () => {
let result = pipe.transform('foo bar baz');
expect(result).toEqual('Foo bar baz');
Expand Down
2 changes: 1 addition & 1 deletion src/app/pipes/string/ucfirst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {isString} from '../helpers/helpers';
@Pipe({name: 'ucfirst'})
export class UcFirstPipe implements PipeTransform {

transform(text: string):string {
transform(text: any):string {
return isString(text)
? (text.slice(0, 1).toUpperCase() + text.slice(1))
: text;
Expand Down
5 changes: 5 additions & 0 deletions src/app/pipes/string/ucwords.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ describe('UcFirstPipe Tests', () => {
pipe = new UcWordsPipe();
});

it('Should return value if not a string', () => {
expect(pipe.transform(42)).toEqual(42);
expect(pipe.transform(false)).toEqual(false);
});

it('Should capitalize all words in a string', () => {
let result = pipe.transform('foo bar baz');
expect(result).toEqual('Foo Bar Baz');
Expand Down
14 changes: 8 additions & 6 deletions src/app/pipes/string/ucwords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import {isString} from '../helpers/helpers';
@Pipe({name: 'ucwords'})
export class UcWordsPipe implements PipeTransform {

transform(text: string): string {
return isString(text)
? text.split(' ')
.map(sub => sub.slice(0, 1).toUpperCase() + sub.slice(1))
.join(' ')
: text;
transform(text: any): string {
if (isString(text)) {
return text.split(' ')
.map((sub: any) => sub.slice(0, 1).toUpperCase() + sub.slice(1))
.join(' ');
}

return text;
}
}

0 comments on commit e80146e

Please sign in to comment.