adriantoine/enzyme-to-json

Type JestSerializer is not matching jest.

VincentLanglet opened this issue · 0 comments

In the index.d.ts, we have

export interface JestSerializer {
  test: (CommonWrapper: CommonWrapper) => boolean;
  print: (CommonWrapper: CommonWrapper, serializer: JestSerializer) => string;
}

export declare function createSerializer(options?: Options): JestSerializer;

But when we use it like this

import { createSerializer } from 'enzyme-to-json';

expect.addSnapshotSerializer(createSerializer());

We receive a typescript error because addSnapshotSerializer is type like this

interface SnapshotSerializerPlugin {
  print(val: any, serialize: ((val: any) => string), indent: ((str: string) => string), opts: SnapshotSerializerOptions, colors: SnapshotSerializerColors): string;
  test(val: any): boolean;
}

addSnapshotSerializer(serializer: SnapshotSerializerPlugin): void;

I think it would be better to type createSerializer like this

/// <reference types="jest"/>

export declare function createSerializer(options?: Options): jest.SnapshotSerializerPlugin