38 lines
1.6 KiB
TypeScript
38 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { RaceName } from './RaceName';
|
|
|
|
describe('RaceName', () => {
|
|
it('creates a valid name and exposes stable value/toString', () => {
|
|
const name = RaceName.fromString('Valid Race Name');
|
|
expect(name.value).toBe('Valid Race Name');
|
|
expect(name.toString()).toBe('Valid Race Name');
|
|
});
|
|
|
|
it('trims leading/trailing whitespace', () => {
|
|
const name = RaceName.fromString(' Valid Race Name ');
|
|
expect(name.value).toBe('Valid Race Name');
|
|
});
|
|
|
|
it('rejects empty/blank values', () => {
|
|
expect(() => RaceName.fromString('')).toThrow('Race name cannot be empty');
|
|
expect(() => RaceName.fromString(' ')).toThrow('Race name cannot be empty');
|
|
});
|
|
|
|
it('rejects names shorter than 3 characters (after trim)', () => {
|
|
expect(() => RaceName.fromString('ab')).toThrow('Race name must be at least 3 characters long');
|
|
expect(() => RaceName.fromString(' ab ')).toThrow('Race name must be at least 3 characters long');
|
|
});
|
|
|
|
it('rejects names longer than 100 characters (after trim)', () => {
|
|
expect(() => RaceName.fromString('a'.repeat(101))).toThrow('Race name must not exceed 100 characters');
|
|
expect(() => RaceName.fromString(` ${'a'.repeat(101)} `)).toThrow('Race name must not exceed 100 characters');
|
|
});
|
|
|
|
it('equals compares by normalized value', () => {
|
|
const a = RaceName.fromString(' Test Race ');
|
|
const b = RaceName.fromString('Test Race');
|
|
const c = RaceName.fromString('Different');
|
|
expect(a.equals(b)).toBe(true);
|
|
expect(a.equals(c)).toBe(false);
|
|
});
|
|
}); |