UNPKG

4.91 kBTypeScriptView Raw
1// Type definitions for chai-enzyme 0.6.1
2// Project: https://github.com/producthunt/chai-enzyme
3// Definitions by: Alexey Svetliakov <https://github.com/asvetliakov>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 3.1
6
7
8/// <reference types="enzyme" />
9/// <reference types="chai" />
10/// <reference types="react" />
11/// <reference types="cheerio" />
12
13declare namespace Chai {
14 type EnzymeSelector = string | React.FunctionComponent<any> | React.ComponentClass<any> | { [key: string]: any };
15
16 interface Match {
17 /**
18 * Assert that the wrapper matches given selector:
19 * @param selector
20 */
21 (selector: EnzymeSelector): Assertion;
22 }
23 interface Include {
24 /**
25 * Assert that the wrapper contains a given node:
26 * @param code
27 */
28 (selector: EnzymeSelector): Assertion;
29
30 /**
31 * Assert that the given wrapper has the supplied text:
32 * @param str
33 */
34 text(str?: string): Assertion;
35 }
36 interface Assertion {
37 /**
38 * Assert that the given wrapper is checked:
39 */
40 checked(): Assertion;
41
42 /**
43 * Assert that the wrapper has a given class:
44 * @param name
45 */
46 className(name: string): Assertion;
47
48 /**
49 * Assert that the wrapper contains a certain element:
50 * @param selector
51 */
52 containMatchingElement(selector: EnzymeSelector): Assertion;
53
54 /**
55 * Assert that the wrapper contains a descendant matching the given selector:
56 * @param selector
57 */
58 descendants(selector?: EnzymeSelector): Assertion;
59
60 /**
61 * Assert that the wrapper contains an exact amount of descendants matching the given selector:
62 */
63 exactly(count?: number): Assertion;
64
65 /**
66 * Assert that the given wrapper is disabled:
67 */
68 disabled(): Assertion;
69
70 /**
71 * Assert that the given wrapper is empty:
72 */
73 blank(): Assertion;
74
75 /**
76 * Assert that the given wrapper exists:
77 */
78 present(): Assertion;
79
80 /**
81 * Assert that the wrapper has given html:
82 * @param str
83 */
84 html(str?: string): Assertion;
85
86 /**
87 * Assert that the wrapper has given ID attribute:
88 * @param str
89 */
90 id(str: string): Assertion;
91
92 /**
93 * Assert that the wrapper has a given ref
94 * @param key
95 */
96 ref(key: string): Assertion;
97
98 /**
99 * Assert that the given wrapper is selected:
100 */
101 selected(): Assertion;
102
103 /**
104 * Assert that the given wrapper has the tag name:
105 * @param str
106 */
107 tagName(str: string): Assertion;
108
109 /**
110 * Assert that the given wrapper has the supplied text:
111 * @param str
112 */
113 text(str?: string): Assertion;
114
115 /**
116 * Assert that the given wrapper has a given type:
117 * @param func
118 */
119 type(func: EnzymeSelector): Assertion;
120
121 /**
122 * Assert that the given wrapper has given value:
123 * @param str
124 */
125 value(str: string): Assertion;
126
127 /**
128 * Assert that the wrapper has given attribute [with value]:
129 * @param key
130 * @param val
131 */
132 attr(key: string, val?: string): Assertion;
133
134 /**
135 * Assert that the wrapper has a given data attribute [with value]:
136 * @param key
137 * @param val
138 */
139 data(key: string, val?: string): Assertion;
140
141 /**
142 * Assert that the wrapper has given style:
143 * @param key
144 * @param val
145 */
146 style(key: string, val?: string): Assertion;
147
148 /**
149 * Assert that the wrapper has given state [with value]:
150 * @param key
151 * @param val
152 */
153 state(key: string, val?: any): Assertion;
154
155 /**
156 * Assert that the wrapper has given prop [with value]:
157 * @param key
158 * @param val
159 */
160 prop(key: string, val?: any): Assertion;
161
162 /**
163 * Assert that the wrapper has given props [with values]:
164 * @param keys
165 */
166 props(keys: string[]): Assertion;
167
168 /**
169 * Assert that the wrapper has given props [with values]:
170 * @param props
171 */
172 props(props: EnzymeSelector): Assertion;
173 }
174}
175
176declare module "chai-enzyme" {
177 import { ShallowWrapper, ReactWrapper } from "enzyme";
178
179 type DebugWrapper = ShallowWrapper<any,any> | cheerio.Cheerio | ReactWrapper<any, any>;
180 function chaiEnzyMe(wrapper?: (debugWrapper: DebugWrapper) => string): Chai.ChaiPlugin;
181
182 module chaiEnzyMe {
183 }
184 export = chaiEnzyMe;
185}