Skip to content

[Bug]: TypeError: Cannot convert object to primitive value when using Signal Forms with Snapshot testing #3560

@cheesi

Description

@cheesi

Version

16.0.0

Steps to reproduce

  1. 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)
  2. npm install
  3. 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:

: `"${compAttrVal}"`) +

The debugger tells me, this is apparently a Proxy(Function) for the myForm:

Image

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)

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions