5
5
* MIT Licensed
6
6
*/
7
7
8
- import { config } from "./config.js" ;
9
- import { AssertionError } from "assertion-error" ;
10
- import * as util from "./utils/index.js" ;
8
+ import { config } from './config.js' ;
9
+ import { AssertionError } from 'assertion-error' ;
10
+ import * as util from './utils/index.js' ;
11
+
12
+ export class Assertion {
13
+ /** @type {{} } */
14
+ __flags = { }
11
15
12
16
/**
13
17
* Creates object for chaining.
@@ -39,51 +43,49 @@ import * as util from "./utils/index.js";
39
43
*
40
44
* - `eql`: This flag contains the deepEqual function to be used by the assertion.
41
45
*
42
- * @param {unknown } ?obj target of the assertion
43
- * @param {string } ?msg (optional) custom error message
44
- * @param {Function } ?ssfi (optional) starting point for removing stack frames
45
- * @param {boolean } ?lockSsfi (optional) whether or not the ssfi flag is locked
46
- * @returns {unknown }
46
+ * @param {unknown } obj target of the assertion
47
+ * @param {string } [msg] (optional) custom error message
48
+ * @param {Function } [ssfi] (optional) starting point for removing stack frames
49
+ * @param {boolean } [lockSsfi] (optional) whether or not the ssfi flag is locked
47
50
*/
48
- export class Assertion {
49
51
constructor ( obj , msg , ssfi , lockSsfi ) {
50
- util . flag ( this , " ssfi" , ssfi || Assertion ) ;
51
- util . flag ( this , " lockSsfi" , lockSsfi ) ;
52
- util . flag ( this , " object" , obj ) ;
53
- util . flag ( this , " message" , msg ) ;
54
- util . flag ( this , " eql" , config . deepEqual || util . eql ) ;
52
+ util . flag ( this , ' ssfi' , ssfi || Assertion ) ;
53
+ util . flag ( this , ' lockSsfi' , lockSsfi ) ;
54
+ util . flag ( this , ' object' , obj ) ;
55
+ util . flag ( this , ' message' , msg ) ;
56
+ util . flag ( this , ' eql' , config . deepEqual || util . eql ) ;
55
57
56
58
return util . proxify ( this ) ;
57
59
}
58
60
59
61
/** @returns {boolean } */
60
62
static get includeStack ( ) {
61
63
console . warn (
62
- " Assertion.includeStack is deprecated, use chai.config.includeStack instead." ,
64
+ ' Assertion.includeStack is deprecated, use chai.config.includeStack instead.'
63
65
) ;
64
66
return config . includeStack ;
65
67
}
66
68
67
69
/** @param {boolean } value */
68
70
static set includeStack ( value ) {
69
71
console . warn (
70
- " Assertion.includeStack is deprecated, use chai.config.includeStack instead." ,
72
+ ' Assertion.includeStack is deprecated, use chai.config.includeStack instead.'
71
73
) ;
72
74
config . includeStack = value ;
73
75
}
74
76
75
77
/** @returns {boolean } */
76
78
static get showDiff ( ) {
77
79
console . warn (
78
- " Assertion.showDiff is deprecated, use chai.config.showDiff instead." ,
80
+ ' Assertion.showDiff is deprecated, use chai.config.showDiff instead.'
79
81
) ;
80
82
return config . showDiff ;
81
83
}
82
84
83
85
/** @param {boolean } value */
84
86
static set showDiff ( value ) {
85
87
console . warn (
86
- " Assertion.showDiff is deprecated, use chai.config.showDiff instead." ,
88
+ ' Assertion.showDiff is deprecated, use chai.config.showDiff instead.'
87
89
) ;
88
90
config . showDiff = value ;
89
91
}
@@ -150,6 +152,7 @@ export class Assertion {
150
152
* @param {unknown } expected value (remember to check for negation)
151
153
* @param {unknown } _actual (optional) will default to `this.obj`
152
154
* @param {boolean } showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
155
+ * @returns {void }
153
156
*/
154
157
assert ( _expr , msg , _negateMsg , expected , _actual , showDiff ) {
155
158
var ok = util . test ( this , arguments ) ;
@@ -160,10 +163,11 @@ export class Assertion {
160
163
if ( ! ok ) {
161
164
msg = util . getMessage ( this , arguments ) ;
162
165
var actual = util . getActual ( this , arguments ) ;
166
+ /** @type {Record<PropertyKey, unknown> } */
163
167
var assertionErrorObjectProperties = {
164
168
actual : actual ,
165
169
expected : expected ,
166
- showDiff : showDiff ,
170
+ showDiff : showDiff
167
171
} ;
168
172
169
173
var operator = util . getOperator ( this , arguments ) ;
@@ -174,7 +178,8 @@ export class Assertion {
174
178
throw new AssertionError (
175
179
msg ,
176
180
assertionErrorObjectProperties ,
177
- config . includeStack ? this . assert : util . flag ( this , "ssfi" ) ,
181
+ // @ts -expect-error Not sure what to do about these types yet
182
+ config . includeStack ? this . assert : util . flag ( this , 'ssfi' )
178
183
) ;
179
184
}
180
185
}
@@ -185,7 +190,7 @@ export class Assertion {
185
190
* @returns {unknown }
186
191
*/
187
192
get _obj ( ) {
188
- return util . flag ( this , " object" ) ;
193
+ return util . flag ( this , ' object' ) ;
189
194
}
190
195
191
196
/**
@@ -194,6 +199,6 @@ export class Assertion {
194
199
* @param {unknown } val
195
200
*/
196
201
set _obj ( val ) {
197
- util . flag ( this , " object" , val ) ;
202
+ util . flag ( this , ' object' , val ) ;
198
203
}
199
204
}
0 commit comments