fix(common): titlecase pipe incorrectly handling numbers (#43476)

Fixes that the `titlecase` pipe wasn't picking up numbers which meant that cases like `1st` would be tranformed to `1St`.

Fixes #43459.

PR Close #43476
This commit is contained in:
Kristiyan Kostadinov
2021-09-19 09:30:10 +02:00
committed by Jessica Janiuk
parent c5d0bd4966
commit df792ebc26
2 changed files with 12 additions and 4 deletions
@@ -90,9 +90,16 @@ import {LowerCasePipe, TitleCasePipe, UpperCasePipe} from '@angular/common';
expect(pipe.transform('éric')).toEqual('Éric');
});
it('should handle numbers at the beginning of words', () => {
expect(pipe.transform('frodo was 1st and bilbo was 2nd'))
.toEqual('Frodo Was 1st And Bilbo Was 2nd');
expect(pipe.transform('1ST')).toEqual('1st');
});
it('should map null to null', () => {
expect(pipe.transform(null)).toEqual(null);
});
it('should map undefined to null', () => {
expect(pipe.transform(undefined)).toEqual(null);
});
@@ -100,6 +107,7 @@ import {LowerCasePipe, TitleCasePipe, UpperCasePipe} from '@angular/common';
it('should not support numbers', () => {
expect(() => pipe.transform(0 as any)).toThrowError();
});
it('should not support other objects', () => {
expect(() => pipe.transform({} as any)).toThrowError();
});