| 380 | }); |
| 381 | |
| 382 | @Component({ |
| 383 | selector: 'test-number-input', |
| 384 | template: ` |
| 385 | <input type="text" [value]="rawValue()" (input)="rawValue.set($event.target.value)" /> |
| 386 | @for (e of errors(); track $index) { |
| 387 | <p class="error">{{ e.message }}</p> |
| 388 | } |
| 389 | `, |
| 390 | }) |
| 391 | class TestNumberInput implements FormValueControl<number | null> { |
| 392 | readonly value = model.required<number | null>(); |
| 393 | readonly errors = input<readonly ValidationError[]>([]); |
| 394 | readonly parseMax = input<number | undefined>(undefined); |
| 395 | |
| 396 | protected readonly rawValue = transformedValue(this.value, { |
| 397 | parse: (rawValue) => { |
| 398 | if (rawValue === '') return {value: null}; |
| 399 | const value = Number(rawValue); |
| 400 | if (Number.isNaN(value)) { |
| 401 | return {error: {kind: 'parse', message: `${rawValue} is not numeric`}}; |
| 402 | } |
| 403 | if (this.parseMax() != null && value > this.parseMax()!) { |
| 404 | return {value, error: [maxError(this.parseMax()!)]}; |
| 405 | } |
| 406 | return {value}; |
| 407 | }, |
| 408 | format: (value) => { |
| 409 | if (value === null || Number.isNaN(value)) return ''; |
| 410 | return value.toString(); |
| 411 | }, |
| 412 | }); |
| 413 | } |
| 414 | |
| 415 | async function act<T>(fn: () => T): Promise<T> { |
| 416 | const result = fn(); |
nothing calls this directly
no test coverage detected
searching dependent graphs…