Version
16.0.0
Steps to reproduce
- Clone reproducable from https://github.com/cheesi/jest-signal-form-bug (I used https://github.com/thymikee/jest-preset-angular/tree/main/examples/example-app-v21 as a base)
- npm install
- npm run test
Expected behavior
No Errors
Actual behavior
toMatchSnapshot fails with an error, when the component uses a Signal Form (form)
Summary of all failing tests
FAIL src/app/my-component/my-component.spec.ts
● MyComponent › should create
TypeError: Cannot convert object to primitive value
19 |
20 | it('should create', () => {
> 21 | expect(fixture).toMatchSnapshot();
| ^
22 | });
23 | });
24 |
at node_modules/jest-preset-angular/build/serializers/ng-snapshot.js:26:27
at Array.map (<anonymous>)
at printPlugin (node_modules/pretty-format/build/index.js:892:111)
at format (node_modules/pretty-format/build/index.js:1028:16)
at __EXTERNAL_MATCHER_TRAP__ (node_modules/expect/build/index.js:2240:22)
at Object.throwingMatcher (node_modules/expect/build/index.js:2241:6)
at src/app/my-component/my-component.spec.ts:21:21
at _ZoneDelegate.invoke (node_modules/zone.js/bundles/zone.umd.js:409:168)
at _ProxyZoneSpec.onInvoke (node_modules/zone.js/bundles/zone-testing.umd.js:1079:43)
at _ZoneDelegate.invoke (node_modules/zone.js/bundles/zone.umd.js:409:56)
at _ZoneImpl.run (node_modules/zone.js/bundles/zone.umd.js:162:47)
at Object.wrappedFunc (node_modules/zone.js/bundles/zone-testing.umd.js:407:38)
Additional context
Relevant component source code:
https://github.com/cheesi/jest-signal-form-bug/blob/main/src/app/my-component/my-component.ts
...
type MyFormModel = {
myProperty: string;
}
@Component({
...
})
export class MyComponent {
private readonly myFormModel = signal<MyFormModel>({
myProperty: ''
});
protected readonly myForm = form(this.myFormModel);
}
Relevant test source:
https://github.com/cheesi/jest-signal-form-bug/blob/main/src/app/my-component/my-component.spec.ts
...
describe('MyComponent', () => {
let component: MyComponent;
let fixture: ComponentFixture<MyComponent>;
beforeEach(async () => {
...
});
it('should create', () => {
expect(fixture).toMatchSnapshot();
});
});
The issue seems to be here:
The debugger tells me, this is apparently a Proxy(Function) for the myForm:
Environment
System:
OS: macOS 26.2
CPU: (12) arm64 Apple M2 Pro
Binaries:
Node: 25.3.0 - /opt/homebrew/bin/node
npm: 11.7.0 - /opt/homebrew/bin/npm
pnpm: 10.28.1 - /Users/MyUser/Library/pnpm/pnpm
npmPackages:
jest: ^30.2.0 => 30.2.0
(Originally discovered on an Ubuntu 22.04 machine)
Version
16.0.0
Steps to reproduce
Expected behavior
No Errors
Actual behavior
toMatchSnapshotfails with an error, when the component uses a Signal Form (form)Additional context
Relevant component source code:
https://github.com/cheesi/jest-signal-form-bug/blob/main/src/app/my-component/my-component.ts
Relevant test source:
https://github.com/cheesi/jest-signal-form-bug/blob/main/src/app/my-component/my-component.spec.ts
The issue seems to be here:
jest-preset-angular/src/serializers/ng-snapshot.ts
Line 46 in 0ce0879
The debugger tells me, this is apparently a
Proxy(Function)for themyForm:Environment
System: OS: macOS 26.2 CPU: (12) arm64 Apple M2 Pro Binaries: Node: 25.3.0 - /opt/homebrew/bin/node npm: 11.7.0 - /opt/homebrew/bin/npm pnpm: 10.28.1 - /Users/MyUser/Library/pnpm/pnpm npmPackages: jest: ^30.2.0 => 30.2.0 (Originally discovered on an Ubuntu 22.04 machine)