Here is the code of test case of custom pipe. I am trying to pass the test of custom made pipe but it's getting failed for some reasons. Also how can i test regex in custom pipe Also how can i test regex in custom pipe
here is live code sample
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'currencyWithDecimal',
})
export class CurrencyWithDecimalPipe implements PipeTransform {
transform(val: string, ...args: any[]) {
return new Intl.NumberFormat('en-IN', {
style: 'currency',
currency: 'INR',
minimumFractionDigits: 0,
}).format(Number(val));
}
}
@Pipe({
name: 'breakAfter',
})
export class BreakAfter implements PipeTransform {
transform(value: string): string {
if (value === '') {
return '';
}
return value.replace(/\n/g, '<br />');
}
}
here is the spec file
import { CurrencyWithDecimalPipe, BreakAfter } from './custom.pipe'
describe('Pipes', () => {
const currencyPipe: CurrencyWithDecimalPipe = new CurrencyWithDecimalPipe();
const breakAfterPipe: BreakAfter = new BreakAfter();
it('should create currencyPipe', () => {
expect(currencyPipe).toBeTruthy();
});
it('should create an breakAfterPipe', () => {
expect(breakAfterPipe).toBeTruthy();
});
describe('currency Pipe', () => {
it('should return currency with decimal value', () => {
expect(currencyPipe.transform('444000').toEqual('4,44,000'))
});
});
describe('break after Pipe', () => {
it('should break after br tag', () => {
expect(breakAfterPipe.transform(`SPEC HAS NO EXPECTATIONS error handler for form validation
ok lets break this.
`).toEqual(`SPEC HAS NO EXPECTATIONS error handler for form validation
ok lets break this`))
});
});
});
Aucun commentaire:
Enregistrer un commentaire