angular/packages/forms/signals/test/node/field_proxy.spec.ts
Miles Malerba 34dd3f647a refactor(forms): rename Field to FieldTree (#64214)
There are two primary reasons for this renaming:
1. It better reflects the actual nature of the proxy object, namely that
   the form is represented as a tree, and that this object is used for
   navigating the tree structure (while `FieldState` is used for getting
   the state at a particular point in the structure).
2. This frees up the name `Field` to be used for the directive that
   binds a `FieldTree` to a UI control.

PR Close #64214
2025-10-03 07:59:31 -07:00

34 lines
1.1 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Injector, signal} from '@angular/core';
import {TestBed} from '@angular/core/testing';
import {form} from '../../public_api';
describe('FieldTree proxy', () => {
it('should not forward methods through the proxy', () => {
const f = form(signal(new Date()), {injector: TestBed.inject(Injector)});
// @ts-expect-error
expect(f.getDate).toBe(undefined as any);
});
it('should allow spreading field arrays', () => {
const f = form(signal([0, 1, 2]), {injector: TestBed.inject(Injector)});
expect([...f].map((i) => i().value())).toEqual([0, 1, 2]);
});
it('should not allow mutation of the field structure', () => {
const f = form(signal({arr: [0, 1]}), {injector: TestBed.inject(Injector)});
// Just to have an expectation, really this test is just to check the typings below.
expect(f).toBeDefined();
// @ts-expect-error
f.arr = f.arr;
// @ts-expect-error
f.arr[0] = f.arr[0];
});
});