MCPcopy Create free account
hub / github.com/angular/angular / TestNumberInput

Class TestNumberInput

packages/forms/signals/test/node/parse_errors.spec.ts:381–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

ComponentInterface · 0.90
transformedValueFunction · 0.85
maxErrorFunction · 0.85
toStringMethod · 0.65
requiredMethod · 0.45

Tested by

no test coverage detected