UNPKG

9.49 kBTypeScriptView Raw
1// Copyright IBM Corp. 2017,2019. All Rights Reserved.
2// Node module: @loopback/testlab
3// This file is licensed under the MIT License.
4// License text available at https://opensource.org/licenses/MIT
5
6// Type definitions for should.js v8.1.1
7// Project: https://github.com/shouldjs/should.js
8// Definitions by: Alex Varju <https://github.com/varju/>, Maxime LUCE <https://github.com/SomaticIT/>
9// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10//
11// NOTICE
12// This project is licensed under the MIT license.
13// Copyrights are respective of each contributor listed at the beginning of each definition file.
14//
15// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16//
17// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21/* We require "should/as-function" to disable Object-prototype manipulation
22interface Object {
23 should: ShouldAssertion;
24}
25*/
26
27/* eslint-disable @typescript-eslint/no-explicit-any */
28/* eslint-disable @typescript-eslint/unified-signatures */
29
30interface ShouldAssertion {
31 // basic grammar
32 a: ShouldAssertion;
33 an: ShouldAssertion;
34 and: ShouldAssertion;
35 be: ShouldAssertion;
36 has: ShouldAssertion;
37 have: ShouldAssertion;
38 is: ShouldAssertion;
39 it: ShouldAssertion;
40 with: ShouldAssertion;
41 which: ShouldAssertion;
42 the: ShouldAssertion;
43 of: ShouldAssertion;
44 not: ShouldAssertion;
45
46 // chai-like expect().to
47 to: ShouldAssertion;
48
49 // validators
50 arguments(): ShouldAssertion;
51 empty(): ShouldAssertion;
52 ok(): ShouldAssertion;
53 true(): ShouldAssertion;
54 false(): ShouldAssertion;
55 NaN(): ShouldAssertion;
56 Infinity(): ShouldAssertion;
57 Array(): ShouldAssertion;
58 Object(): ShouldAssertion;
59 String(): ShouldAssertion;
60 Boolean(): ShouldAssertion;
61 Number(): ShouldAssertion;
62 Error(): ShouldAssertion;
63 Function(): ShouldAssertion;
64 Date(): ShouldAssertion;
65 Class(): ShouldAssertion;
66 Undefined(): ShouldAssertion;
67 Null(): ShouldAssertion;
68 Promise(): ShouldAssertion;
69 generator(): ShouldAssertion;
70 iterable(): ShouldAssertion;
71 iterator(): ShouldAssertion;
72 eql(expected: any, description?: string): ShouldAssertion;
73 equal(expected: any, description?: string): ShouldAssertion;
74 equalOneOf(...values: any[]): ShouldAssertion;
75 within(start: number, finish: number, description?: string): ShouldAssertion;
76 approximately(
77 value: number,
78 delta: number,
79 description?: string,
80 ): ShouldAssertion;
81 type(expected: any, description?: string): ShouldAssertion;
82 instanceof(constructor: Function, description?: string): ShouldAssertion;
83 above(n: number, description?: string): ShouldAssertion;
84 below(n: number, description?: string): ShouldAssertion;
85 aboveOrEqual(n: number, description?: string): ShouldAssertion;
86 greaterThanOrEqual(n: number, description?: string): ShouldAssertion;
87 belowOrEqual(n: number, description?: string): ShouldAssertion;
88 lessThanOrEqual(n: number, description?: string): ShouldAssertion;
89 match(other: {}, description?: string): ShouldAssertion;
90 match(other: (val: any) => any, description?: string): ShouldAssertion;
91 match(regexp: RegExp, description?: string): ShouldAssertion;
92 match(other: any, description?: string): ShouldAssertion;
93 matchEach(other: {}, description?: string): ShouldAssertion;
94 matchEach(other: (val: any) => any, description?: string): ShouldAssertion;
95 matchEach(regexp: RegExp, description?: string): ShouldAssertion;
96 matchEach(other: any, description?: string): ShouldAssertion;
97 matchAny(other: {}, description?: string): ShouldAssertion;
98 matchAny(other: (val: any) => any, description?: string): ShouldAssertion;
99 matchAny(regexp: RegExp, description?: string): ShouldAssertion;
100 matchAny(other: any, description?: string): ShouldAssertion;
101 length(n: number, description?: string): ShouldAssertion;
102 property(name: string, description?: string): ShouldAssertion;
103 property(name: string, val: any, description?: string): ShouldAssertion;
104 properties(names: string[]): ShouldAssertion;
105 properties(name: string): ShouldAssertion;
106 properties(descriptor: any): ShouldAssertion;
107 properties(...properties: string[]): ShouldAssertion;
108 propertyByPath(...properties: string[]): ShouldAssertion;
109 propertyWithDescriptor(
110 name: string,
111 descriptor: PropertyDescriptor,
112 ): ShouldAssertion;
113 oneOf(...values: any[]): ShouldAssertion;
114 ownProperty(name: string, description?: string): ShouldAssertion;
115 containEql(obj: any): ShouldAssertion;
116 containDeep(obj: any): ShouldAssertion;
117 containDeepOrdered(obj: any): ShouldAssertion;
118 keys(...allKeys: string[]): ShouldAssertion;
119 keys(allKeys: string[]): ShouldAssertion;
120 enumerable(property: string, value?: any): ShouldAssertion;
121 enumerables(...properties: string[]): ShouldAssertion;
122 startWith(expected: string, message?: any): ShouldAssertion;
123 endWith(expected: string, message?: any): ShouldAssertion;
124 throw(propereties?: {}): ShouldAssertion;
125 throw(message: Function | string | RegExp, properties?: {}): ShouldAssertion;
126
127 //promises
128 eventually: ShouldAssertion;
129 finally: ShouldAssertion;
130 fulfilled(): Promise<any>;
131 fulfilledWith(value: any): Promise<any>;
132 rejected(): Promise<any>;
133 rejectedWith(err: Function | string | RegExp, properties?: {}): Promise<any>;
134 rejectedWith(properties: {}): Promise<any>;
135
136 //http
137 header(field: string, val?: string): ShouldAssertion;
138 status(code: number): ShouldAssertion;
139 json(): ShouldAssertion;
140 html(): ShouldAssertion;
141
142 //stubs
143 alwaysCalledOn(thisTarget: any): ShouldAssertion;
144 alwaysCalledWith(...arguments: any[]): ShouldAssertion;
145 alwaysCalledWithExactly(...arguments: any[]): ShouldAssertion;
146 alwaysCalledWithMatch(...arguments: any[]): ShouldAssertion;
147 alwaysCalledWithNew(): ShouldAssertion;
148 alwaysThrew(exception?: any): ShouldAssertion;
149 callCount(count: number): ShouldAssertion;
150 called(): ShouldAssertion;
151 calledOn(thisTarget: any): ShouldAssertion;
152 calledOnce(): ShouldAssertion;
153 calledTwice(): ShouldAssertion;
154 calledThrice(): ShouldAssertion;
155 calledWith(...arguments: any[]): ShouldAssertion;
156 calledWithExactly(...arguments: any[]): ShouldAssertion;
157 calledWithMatch(...arguments: any[]): ShouldAssertion;
158 calledWithNew(): ShouldAssertion;
159 neverCalledWith(...arguments: any[]): ShouldAssertion;
160 neverCalledWithMatch(...arguments: any[]): ShouldAssertion;
161 threw(exception?: any): ShouldAssertion;
162
163 // aliases
164 True(): ShouldAssertion;
165 False(): ShouldAssertion;
166 Arguments(): ShouldAssertion;
167 class(): ShouldAssertion;
168 deepEqual(expected: any, description?: string): ShouldAssertion;
169 exactly(expected: any, description?: string): ShouldAssertion;
170 instanceOf(constructor: Function, description?: string): ShouldAssertion;
171 throwError(message?: any): ShouldAssertion;
172 lengthOf(n: number, description?: string): ShouldAssertion;
173 key(key: string): ShouldAssertion;
174 hasOwnProperty(name: string, description?: string): ShouldAssertion;
175 greaterThan(n: number, description?: string): ShouldAssertion;
176 lessThan(n: number, description?: string): ShouldAssertion;
177 null(): ShouldAssertion;
178 undefined(): ShouldAssertion;
179}
180
181interface ShouldInternal {
182 // should.js's extras
183 exist(actual: any, msg?: string): void;
184 exists(actual: any, msg?: string): void;
185 not: ShouldInternal;
186}
187
188interface Assertion {
189 add(name: string, func: Function): void;
190 addChain(name: string, onCall?: Function): void;
191 alias(from: string, to: string): void;
192}
193
194interface Internal extends ShouldInternal {
195 (obj: any): ShouldAssertion;
196
197 // Simple utility function for a bit more easier should assertion extension
198 use(fn: (should: Internal, Assertion: Assertion) => void): Internal;
199
200 // node.js's assert functions
201 fail(actual: any, expected: any, message: string, operator: string): void;
202 assert(value: any, message: string): void;
203 ok(value: any, message?: string): void;
204 equal(actual: any, expected: any, message?: string): void;
205 notEqual(actual: any, expected: any, message?: string): void;
206 deepEqual(actual: any, expected: any, message?: string): void;
207 notDeepEqual(actual: any, expected: any, message?: string): void;
208 strictEqual(actual: any, expected: any, message?: string): void;
209 notStrictEqual(actual: any, expected: any, message?: string): void;
210 throws(block: any, error?: any, message?: string): void;
211 doesNotThrow(block: any, message?: string): void;
212 ifError(value: any): void;
213 inspect(value: any, obj: any): any;
214}
215
216declare var should: Internal;
217interface Window {
218 Should: Internal;
219}
220
221declare module 'should' {
222 export = should;
223}