UNPKG

2.48 kBTypeScriptView Raw
1/// <reference types="cheerio" />
2import {CommonWrapper, ShallowWrapper, ReactWrapper} from 'enzyme';
3
4export interface Json {
5 type: string;
6 props: {[key: string]: any};
7 children: Array<Json>;
8 $$typeof: Symbol;
9}
10
11export interface OutputMapper {
12 (json: Json): Json;
13}
14
15export interface Options {
16 ignoreDefaultProps?: boolean;
17 map?: OutputMapper;
18 noKey?: boolean;
19 mode?: 'shallow' | 'deep';
20}
21
22export interface JestSerializer {
23 test: (CommonWrapper: CommonWrapper) => boolean;
24 print: (CommonWrapper: CommonWrapper, serializer: JestSerializer) => Json;
25}
26
27/**
28 * toJson helper is used to convert any Enzyme wrapper to a format compatible with Jest snapshot
29 * @param wrapper any Enzyme wrapper
30 * @param [options] an option object which accepts `map`, `noKey` and `mode` as keys
31 */
32export declare function toJson(wrapper: CommonWrapper | cheerio.Cheerio, options?: Options): Json;
33export declare function toJson<P, S>(wrapper: CommonWrapper<P, S> | cheerio.Cheerio, options?: Options): Json;
34
35/**
36 * shallowToJson helper is used to convert Enzyme shallow wrappers to a format compatible with Jest snapshot
37 * @param wrapper an Enzyme shallow wrapper
38 * @param [options] an option object which accepts `map`, `noKey` and `mode` as keys
39 */
40export declare function shallowToJson(wrapper: ShallowWrapper, options?: Options,): Json;
41export declare function shallowToJson<P, S>(wrapper: ShallowWrapper<P, S>, options?: Options,): Json;
42
43/**
44 * mountToJson helper is used to convert Enzyme mount wrappers to a format compatible with Jest snapshot
45 * @param wrapper an Enzyme mount wrapper
46 * @param [options] an option object which accepts `map`, `noKey` and `mode` as keys
47 */
48export declare function mountToJson(wrapper: ReactWrapper, options?: Options): Json;
49export declare function mountToJson<P, S>(wrapper: ReactWrapper<P, S>, options?: Options): Json;
50
51/**
52 * renderToJson helper is used to convert Enzyme render wrappers to a format compatible with Jest snapshot
53 * @param wrapper an Enzyme render wrapper
54 * @param [options] an option object which accepts `map`, `noKey` and `mode` as keys
55 */
56export declare function renderToJson(wrapper: cheerio.Cheerio, options?: Options): Json;
57
58/**
59 * createSerializer helper is used to create snapshot serializers for Jest
60 * @param [options] an option object which accepts `map`, `noKey` and `mode` as keys
61 */
62export declare function createSerializer(options?: Options): JestSerializer;
63
64export default toJson;