adriantoine / enzyme-to-json

Snapshot test your Enzyme wrappers
MIT License
947 stars 64 forks source link

Type JestSerializer is not matching jest. #126

Open VincentLanglet opened 5 years ago

VincentLanglet commented 5 years ago

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