enzyme-to-json icon indicating copy to clipboard operation
enzyme-to-json copied to clipboard

Type JestSerializer is not matching jest.

Open VincentLanglet opened this issue 5 years ago • 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

VincentLanglet avatar Jan 30 '19 16:01 VincentLanglet