1- const output = require ( '../output' )
1+ import * as output from '../output.js' ;
22
3- let expect
3+ import { expect } from 'chai'
44
55import ( 'chai' ) . then ( ( chai ) => {
6- expect = chai . expect
76 chai . use ( require ( 'chai-string' ) )
87 // @ts -ignore
98 chai . use ( require ( 'chai-exclude' ) )
@@ -39,7 +38,7 @@ class ExpectHelper {
3938 */
4039 expectEqual ( actualValue , expectedValue , customErrorMsg = '' ) {
4140 // @ts -ignore
42- output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to equal "${ JSON . stringify ( expectedValue ) } "` )
41+ output . output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to equal "${ JSON . stringify ( expectedValue ) } "` )
4342 return expect ( actualValue , customErrorMsg ) . to . equal ( expectedValue )
4443 }
4544
@@ -51,7 +50,7 @@ class ExpectHelper {
5150 */
5251 expectNotEqual ( actualValue , expectedValue , customErrorMsg = '' ) {
5352 // @ts -ignore
54- output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to not equal "${ JSON . stringify ( expectedValue ) } "` )
53+ output . output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to not equal "${ JSON . stringify ( expectedValue ) } "` )
5554 return expect ( actualValue , customErrorMsg ) . not . to . equal ( expectedValue )
5655 }
5756
@@ -64,7 +63,7 @@ class ExpectHelper {
6463 */
6564 expectDeepEqual ( actualValue , expectedValue , customErrorMsg = '' ) {
6665 // @ts -ignore
67- output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to deep equal "${ JSON . stringify ( expectedValue ) } "` )
66+ output . output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to deep equal "${ JSON . stringify ( expectedValue ) } "` )
6867 return expect ( actualValue , customErrorMsg ) . to . deep . equal ( expectedValue )
6968 }
7069
@@ -76,7 +75,7 @@ class ExpectHelper {
7675 */
7776 expectNotDeepEqual ( actualValue , expectedValue , customErrorMsg = '' ) {
7877 // @ts -ignore
79- output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to not deep equal "${ JSON . stringify ( expectedValue ) } "` )
78+ output . output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to not deep equal "${ JSON . stringify ( expectedValue ) } "` )
8079 return expect ( actualValue , customErrorMsg ) . to . not . deep . equal ( expectedValue )
8180 }
8281
@@ -88,7 +87,7 @@ class ExpectHelper {
8887 */
8988 expectContain ( actualValue , expectedValueToContain , customErrorMsg = '' ) {
9089 // @ts -ignore
91- output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to contain "${ JSON . stringify ( expectedValueToContain ) } "` )
90+ output . output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to contain "${ JSON . stringify ( expectedValueToContain ) } "` )
9291 return expect ( actualValue , customErrorMsg ) . to . contain ( expectedValueToContain )
9392 }
9493
@@ -100,7 +99,7 @@ class ExpectHelper {
10099 */
101100 expectNotContain ( actualValue , expectedValueToNotContain , customErrorMsg = '' ) {
102101 // @ts -ignore
103- output . step (
102+ output . output . step (
104103 `I expect "${ JSON . stringify ( actualValue ) } " to not contain "${ JSON . stringify ( expectedValueToNotContain ) } "` ,
105104 )
106105 return expect ( actualValue , customErrorMsg ) . not . to . contain ( expectedValueToNotContain )
@@ -113,23 +112,32 @@ class ExpectHelper {
113112 * @param {* } [customErrorMsg]
114113 */
115114 expectStartsWith ( actualValue , expectedValueToStartWith , customErrorMsg = '' ) {
116- // @ts -ignore
117- output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to start with "${ JSON . stringify ( expectedValueToStartWith ) } "` )
118- return expect ( actualValue , customErrorMsg ) . to . startsWith ( expectedValueToStartWith )
115+ // Log the step output
116+ output . output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to start with "${ JSON . stringify ( expectedValueToStartWith ) } "` ) ;
117+
118+ // Check if actualValue is a string
119+ expect ( actualValue , customErrorMsg ) . to . be . a ( 'string' ) ;
120+
121+ // Check if actualValue starts with expectedValueToStartWith
122+ expect ( actualValue . startsWith ( expectedValueToStartWith ) , customErrorMsg ) . to . be . true ;
119123 }
120124
125+
121126 /**
122127 *
123128 * @param {* } actualValue
124129 * @param {* } expectedValueToNotStartWith
125130 * @param {* } [customErrorMsg]
126131 */
127132 expectNotStartsWith ( actualValue , expectedValueToNotStartWith , customErrorMsg = '' ) {
128- // @ts -ignore
129- output . step (
130- `I expect "${ JSON . stringify ( actualValue ) } " to not start with "${ JSON . stringify ( expectedValueToNotStartWith ) } "` ,
131- )
132- return expect ( actualValue , customErrorMsg ) . not . to . startsWith ( expectedValueToNotStartWith )
133+ // Log the step output
134+ output . output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to not start with "${ JSON . stringify ( expectedValueToNotStartWith ) } "` ) ;
135+
136+ // Check if actualValue is a string
137+ expect ( actualValue , customErrorMsg ) . to . be . a ( 'string' ) ;
138+
139+ // Check if actualValue starts with expectedValueToStartWith
140+ expect ( actualValue . startsWith ( expectedValueToNotStartWith ) , customErrorMsg ) . to . be . false ;
133141 }
134142
135143 /**
@@ -139,7 +147,7 @@ class ExpectHelper {
139147 */
140148 expectEndsWith ( actualValue , expectedValueToEndWith , customErrorMsg = '' ) {
141149 // @ts -ignore
142- output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to end with "${ JSON . stringify ( expectedValueToEndWith ) } "` )
150+ output . output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to end with "${ JSON . stringify ( expectedValueToEndWith ) } "` )
143151 return expect ( actualValue , customErrorMsg ) . to . endsWith ( expectedValueToEndWith )
144152 }
145153
@@ -150,7 +158,7 @@ class ExpectHelper {
150158 */
151159 expectNotEndsWith ( actualValue , expectedValueToNotEndWith , customErrorMsg = '' ) {
152160 // @ts -ignore
153- output . step (
161+ output . output . step (
154162 `I expect "${ JSON . stringify ( actualValue ) } " to not end with "${ JSON . stringify ( expectedValueToNotEndWith ) } "` ,
155163 )
156164 return expect ( actualValue , customErrorMsg ) . not . to . endsWith ( expectedValueToNotEndWith )
@@ -163,7 +171,7 @@ class ExpectHelper {
163171 */
164172 expectJsonSchema ( targetData , jsonSchema , customErrorMsg = '' ) {
165173 // @ts -ignore
166- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to match this JSON schema "${ JSON . stringify ( jsonSchema ) } "` )
174+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to match this JSON schema "${ JSON . stringify ( jsonSchema ) } "` )
167175
168176 return expect ( targetData , customErrorMsg ) . to . be . jsonSchema ( jsonSchema )
169177 }
@@ -176,7 +184,7 @@ class ExpectHelper {
176184 */
177185 expectJsonSchemaUsingAJV ( targetData , jsonSchema , customErrorMsg = '' , ajvOptions = { allErrors : true } ) {
178186 // @ts -ignore
179- output . step (
187+ output . output . step (
180188 `I expect "${ JSON . stringify ( targetData ) } " to match this JSON schema using AJV "${ JSON . stringify ( jsonSchema ) } "` ,
181189 )
182190 chai . use ( require ( 'chai-json-schema-ajv' ) . create ( ajvOptions ) )
@@ -190,7 +198,7 @@ class ExpectHelper {
190198 */
191199 expectHasProperty ( targetData , propertyName , customErrorMsg = '' ) {
192200 // @ts -ignore
193- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to have property: "${ JSON . stringify ( propertyName ) } "` )
201+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to have property: "${ JSON . stringify ( propertyName ) } "` )
194202 return expect ( targetData , customErrorMsg ) . to . have . property ( propertyName )
195203 }
196204
@@ -201,7 +209,7 @@ class ExpectHelper {
201209 */
202210 expectHasAProperty ( targetData , propertyName , customErrorMsg = '' ) {
203211 // @ts -ignore
204- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to have a property: "${ JSON . stringify ( propertyName ) } "` )
212+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to have a property: "${ JSON . stringify ( propertyName ) } "` )
205213 return expect ( targetData , customErrorMsg ) . to . have . a . property ( propertyName )
206214 }
207215
@@ -212,7 +220,7 @@ class ExpectHelper {
212220 */
213221 expectToBeA ( targetData , type , customErrorMsg = '' ) {
214222 // @ts -ignore
215- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be a "${ JSON . stringify ( type ) } "` )
223+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be a "${ JSON . stringify ( type ) } "` )
216224 return expect ( targetData , customErrorMsg ) . to . be . a ( type )
217225 }
218226
@@ -223,7 +231,7 @@ class ExpectHelper {
223231 */
224232 expectToBeAn ( targetData , type , customErrorMsg = '' ) {
225233 // @ts -ignore
226- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be an "${ JSON . stringify ( type ) } "` )
234+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be an "${ JSON . stringify ( type ) } "` )
227235 return expect ( targetData , customErrorMsg ) . to . be . an ( type )
228236 }
229237
@@ -234,7 +242,7 @@ class ExpectHelper {
234242 */
235243 expectMatchRegex ( targetData , regex , customErrorMsg = '' ) {
236244 // @ts -ignore
237- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to match the regex "${ JSON . stringify ( regex ) } "` )
245+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to match the regex "${ JSON . stringify ( regex ) } "` )
238246 return expect ( targetData , customErrorMsg ) . to . match ( regex )
239247 }
240248
@@ -245,7 +253,7 @@ class ExpectHelper {
245253 */
246254 expectLengthOf ( targetData , length , customErrorMsg = '' ) {
247255 // @ts -ignore
248- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to have length of "${ JSON . stringify ( length ) } "` )
256+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to have length of "${ JSON . stringify ( length ) } "` )
249257 return expect ( targetData , customErrorMsg ) . to . have . lengthOf ( length )
250258 }
251259
@@ -255,7 +263,7 @@ class ExpectHelper {
255263 */
256264 expectEmpty ( targetData , customErrorMsg = '' ) {
257265 // @ts -ignore
258- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be empty` )
266+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be empty` )
259267 return expect ( targetData , customErrorMsg ) . to . be . empty
260268 }
261269
@@ -265,7 +273,7 @@ class ExpectHelper {
265273 */
266274 expectTrue ( targetData , customErrorMsg = '' ) {
267275 // @ts -ignore
268- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be true` )
276+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be true` )
269277 return expect ( targetData , customErrorMsg ) . to . be . true
270278 }
271279
@@ -275,7 +283,7 @@ class ExpectHelper {
275283 */
276284 expectFalse ( targetData , customErrorMsg = '' ) {
277285 // @ts -ignore
278- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be false` )
286+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be false` )
279287 return expect ( targetData , customErrorMsg ) . to . be . false
280288 }
281289
@@ -286,7 +294,7 @@ class ExpectHelper {
286294 */
287295 expectAbove ( targetData , aboveThan , customErrorMsg = '' ) {
288296 // @ts -ignore
289- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be above ${ JSON . stringify ( aboveThan ) } ` )
297+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be above ${ JSON . stringify ( aboveThan ) } ` )
290298 return expect ( targetData , customErrorMsg ) . to . be . above ( aboveThan )
291299 }
292300
@@ -297,7 +305,7 @@ class ExpectHelper {
297305 */
298306 expectBelow ( targetData , belowThan , customErrorMsg = '' ) {
299307 // @ts -ignore
300- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be below ${ JSON . stringify ( belowThan ) } ` )
308+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to be below ${ JSON . stringify ( belowThan ) } ` )
301309 return expect ( targetData , customErrorMsg ) . to . be . below ( belowThan )
302310 }
303311
@@ -308,7 +316,7 @@ class ExpectHelper {
308316 */
309317 expectLengthAboveThan ( targetData , lengthAboveThan , customErrorMsg = '' ) {
310318 // @ts -ignore
311- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to have length of above ${ JSON . stringify ( lengthAboveThan ) } ` )
319+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to have length of above ${ JSON . stringify ( lengthAboveThan ) } ` )
312320 return expect ( targetData , customErrorMsg ) . to . have . lengthOf . above ( lengthAboveThan )
313321 }
314322
@@ -319,7 +327,7 @@ class ExpectHelper {
319327 */
320328 expectLengthBelowThan ( targetData , lengthBelowThan , customErrorMsg = '' ) {
321329 // @ts -ignore
322- output . step ( `I expect "${ JSON . stringify ( targetData ) } " to have length of below ${ JSON . stringify ( lengthBelowThan ) } ` )
330+ output . output . step ( `I expect "${ JSON . stringify ( targetData ) } " to have length of below ${ JSON . stringify ( lengthBelowThan ) } ` )
323331 return expect ( targetData , customErrorMsg ) . to . have . lengthOf . below ( lengthBelowThan )
324332 }
325333
@@ -330,7 +338,7 @@ class ExpectHelper {
330338 */
331339 expectEqualIgnoreCase ( actualValue , expectedValue , customErrorMsg = '' ) {
332340 // @ts -ignore
333- output . step ( `I expect and ingore case "${ JSON . stringify ( actualValue ) } " to equal "${ JSON . stringify ( expectedValue ) } "` )
341+ output . output . step ( `I expect and ingore case "${ JSON . stringify ( actualValue ) } " to equal "${ JSON . stringify ( expectedValue ) } "` )
334342 return expect ( actualValue , customErrorMsg ) . to . equalIgnoreCase ( expectedValue )
335343 }
336344
@@ -342,7 +350,7 @@ class ExpectHelper {
342350 */
343351 expectDeepMembers ( actualValue , expectedValue , customErrorMsg = '' ) {
344352 // @ts -ignore
345- output . step (
353+ output . output . step (
346354 `I expect members of "${ JSON . stringify ( actualValue ) } " and "${ JSON . stringify ( expectedValue ) } " arrays are deeply equal` ,
347355 )
348356 return expect ( actualValue , customErrorMsg ) . to . have . deep . members ( expectedValue )
@@ -356,7 +364,7 @@ class ExpectHelper {
356364 */
357365 expectDeepIncludeMembers ( superset , set , customErrorMsg = '' ) {
358366 // @ts -ignore
359- output . step ( `I expect "${ JSON . stringify ( superset ) } " array to be a superset of "${ JSON . stringify ( set ) } " array` )
367+ output . output . step ( `I expect "${ JSON . stringify ( superset ) } " array to be a superset of "${ JSON . stringify ( set ) } " array` )
360368 return expect ( superset , customErrorMsg ) . to . deep . include . members ( set )
361369 }
362370
@@ -369,7 +377,7 @@ class ExpectHelper {
369377 */
370378 expectDeepEqualExcluding ( actualValue , expectedValue , fieldsToExclude , customErrorMsg = '' ) {
371379 // @ts -ignore
372- output . step (
380+ output . output . step (
373381 `I expect members of "${ JSON . stringify ( actualValue ) } " and "${ JSON . stringify ( expectedValue ) } " JSON objects are deeply equal excluding properties: ${ JSON . stringify ( fieldsToExclude ) } ` ,
374382 )
375383 return expect ( actualValue , customErrorMsg ) . excludingEvery ( fieldsToExclude ) . to . deep . equal ( expectedValue )
@@ -383,9 +391,9 @@ class ExpectHelper {
383391 */
384392 expectMatchesPattern ( actualValue , expectedPattern , customErrorMsg = '' ) {
385393 // @ts -ignore
386- output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to match the ${ JSON . stringify ( expectedPattern ) } pattern` )
394+ output . output . step ( `I expect "${ JSON . stringify ( actualValue ) } " to match the ${ JSON . stringify ( expectedPattern ) } pattern` )
387395 return expect ( actualValue , customErrorMsg ) . to . matchPattern ( expectedPattern )
388396 }
389397}
390398
391- module . exports = ExpectHelper
399+ export default ExpectHelper
0 commit comments