569d887d1e
Renaming the package so any further PRs directed to the website are targeted to the reworked code instead of diverging. Once merged, I will start preparing this for deployment to dev to test before releasing to prod. Any improvements will also be applied to this package. I avoided making significant changes to API routes so nothing breaks, but will test it thoroughly today to confirm. That said, everything is ported - double checked. Big diff PR, impossible to review, but last one! No more rebuilds.
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { splitFullName } from './split-full-name';
|
|
|
|
describe('splitFullName', () => {
|
|
it('splits a standard "first last" name', () => {
|
|
expect(splitFullName('John Doe')).toEqual({
|
|
firstName: 'John',
|
|
lastName: 'Doe',
|
|
});
|
|
});
|
|
|
|
it('returns an empty lastName for a single-token name', () => {
|
|
expect(splitFullName('Madonna')).toEqual({
|
|
firstName: 'Madonna',
|
|
lastName: '',
|
|
});
|
|
});
|
|
|
|
it('keeps middle and additional names in lastName', () => {
|
|
expect(splitFullName('John Michael Doe')).toEqual({
|
|
firstName: 'John',
|
|
lastName: 'Michael Doe',
|
|
});
|
|
});
|
|
|
|
it('collapses arbitrary whitespace between tokens', () => {
|
|
expect(splitFullName(' John Doe ')).toEqual({
|
|
firstName: 'John',
|
|
lastName: 'Doe',
|
|
});
|
|
});
|
|
|
|
it('treats tabs and newlines as separators', () => {
|
|
expect(splitFullName('John\t\nDoe')).toEqual({
|
|
firstName: 'John',
|
|
lastName: 'Doe',
|
|
});
|
|
});
|
|
|
|
it('returns empty fields for an empty or whitespace-only string', () => {
|
|
expect(splitFullName('')).toEqual({ firstName: '', lastName: '' });
|
|
expect(splitFullName(' ')).toEqual({ firstName: '', lastName: '' });
|
|
});
|
|
});
|