/
githubmirror
/
nest
Обзор
Документация
Войти
/
githubmirror
/
nest
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
packages/common/test/pipes/parse-float.pipe.spec.ts
44 строки
1 KB
Kamil Myśliwiec
build: use strict null checks part 3
26 ноя 2024, 15:49
Не верифицирован
26 ноя 2024, 15:49
b94b0b9
Код
Авторство
О чём код?
import { expect } from 'chai'; import { HttpException } from '../../exceptions'; import { ArgumentMetadata } from '../../interfaces'; import { ParseFloatPipe } from '../../pipes/parse-float.pipe'; class CustomTestError extends HttpException { constructor() { super('This is a TestException', 418); } } describe('ParseFloatPipe', () => { let target: ParseFloatPipe; beforeEach(() => { target = new ParseFloatPipe({ exceptionFactory: (error: any) => new CustomTestError(), }); }); describe('transform', () => { describe('when validation passes', () => { it('should return number', async () => { const num = '3.33'; expect(await target.transform(num, {} as ArgumentMetadata)).to.equal( parseFloat(num), ); }); it('should not throw an error if the value is undefined/null and optional is true', async () => { const target = new ParseFloatPipe({ optional: true }); const value = await target.transform( undefined!, {} as ArgumentMetadata, ); expect(value).to.equal(undefined); }); }); describe('when validation fails', () => { it('should throw an error', async () => { return expect( target.transform('123.123abc', {} as ArgumentMetadata), ).to.be.rejectedWith(CustomTestError); }); }); }); });