Skip to content

TypeScript error when passing enzymeToJson to setSerializers #108

Closed
@simonsmith

Description

@simonsmith

Hello, here is my setup code:

test-setup.ts

import * as snapshotDiff from 'snapshot-diff';

// This is the same function exposed in `enzyme-to-json/serializer' as per README
import { createSerializer } from 'enzyme-to-json'; 

const enzymeToJsonSerializer = createSerializer();
snapshotDiff.setSerializers([enzymeToJsonSerializer]);

This produces the following error:

error TS2741: Property 'diffOptions' is missing in type 'JestSerializer' but required in type 'Serializer'.

This seems like a mismatch between the Serializer type in this repository and the JestSerializer type from enzyme-to-json.

My understanding is that a serializer should only have two required properties (print and test) so perhaps diffOptions needs to be optional? Note that it appears the source code expects it to be optional already

If I try to make that change I get:

 error TS2322: Type 'JestSerializer' is not assignable to type 'Serializer'.
  Types of property 'print' are incompatible.
    Type '(CommonWrapper: CommonWrapper<{}, {}, Component<{}, {}, any>>, serializer: JestSerializer) => Json' is not assignable to type '(value: any, _serializer?: Function | undefined) => string'.
      Types of parameters 'serializer' and '_serializer' are incompatible.
        Type 'Function | undefined' is not assignable to type 'JestSerializer'.
          Type 'undefined' is not assignable to type 'JestSerializer'.

Let me know if I can provide further debugging help, thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions