@@ -1322,20 +1322,16 @@ expectPrototype.setErrorMessage = function (err) {
1322
1322
1323
1323
expectPrototype . addAdditionalPromiseMethods = function (
1324
1324
promise ,
1325
- expect ,
1326
1325
subject ,
1327
- args ,
1328
- wrappedExpect
1329
1326
) {
1327
+ const stack = new Error ( 'hey' ) . stack ;
1328
+ const wrappedExpect = this ;
1329
+ const expect = this . _topLevelExpect ;
1330
1330
// const expect = this;
1331
1331
promise . and = function ( ...args ) {
1332
1332
function executeAnd ( ) {
1333
1333
if ( expect . findTypeOf ( args [ 0 ] ) . is ( 'expect.it' ) ) {
1334
- return expect . addAdditionalPromiseMethods (
1335
- args [ 0 ] ( subject ) ,
1336
- expect ,
1337
- subject
1338
- ) ;
1334
+ return expect . addAdditionalPromiseMethods ( args [ 0 ] ( subject ) , subject ) ;
1339
1335
} else {
1340
1336
return expect ( subject , ...args ) ;
1341
1337
}
@@ -1344,11 +1340,7 @@ expectPrototype.addAdditionalPromiseMethods = function (
1344
1340
if ( this . isFulfilled ( ) ) {
1345
1341
return executeAnd ( ) ;
1346
1342
} else {
1347
- return expect . addAdditionalPromiseMethods (
1348
- this . then ( executeAnd ) ,
1349
- expect ,
1350
- subject
1351
- ) ;
1343
+ return expect . addAdditionalPromiseMethods ( this . then ( executeAnd ) , subject ) ;
1352
1344
}
1353
1345
} ;
1354
1346
@@ -1359,14 +1351,13 @@ expectPrototype.addAdditionalPromiseMethods = function (
1359
1351
if ( expect . findTypeOf ( args [ 0 ] ) . is ( 'expect.it' ) ) {
1360
1352
return expect . addAdditionalPromiseMethods (
1361
1353
args [ 0 ] ( shiftedSubject ) ,
1362
- expect ,
1363
1354
subject
1364
1355
) ;
1365
1356
} else {
1366
- if ( wrappedExpect ) {
1357
+ if ( wrappedExpect !== expect ) {
1367
1358
return wrappedExpect . shifty (
1368
1359
shiftedSubject ,
1369
- wrappedExpect . args || [ ] ,
1360
+ wrappedExpect . args ,
1370
1361
[
1371
1362
methodName . replace ( / [ A - Z ] / g, ( $0 ) => ` ${ $0 . toLowerCase ( ) } ` ) ,
1372
1363
...args ,
@@ -1389,11 +1380,7 @@ expectPrototype.addAdditionalPromiseMethods = function (
1389
1380
if ( this . isFulfilled ( ) ) {
1390
1381
return execute ( this . value ( ) ) ;
1391
1382
} else {
1392
- return expect . addAdditionalPromiseMethods (
1393
- this . then ( execute ) ,
1394
- expect ,
1395
- subject
1396
- ) ;
1383
+ return expect . addAdditionalPromiseMethods ( this . then ( execute ) , subject ) ;
1397
1384
}
1398
1385
} ;
1399
1386
@@ -1403,7 +1390,6 @@ expectPrototype.addAdditionalPromiseMethods = function (
1403
1390
if ( expect . findTypeOf ( args [ 0 ] ) . is ( 'expect.it' ) ) {
1404
1391
return expect . addAdditionalPromiseMethods (
1405
1392
args [ 0 ] ( subject ) ,
1406
- expect ,
1407
1393
subject
1408
1394
) ;
1409
1395
} else {
@@ -1416,7 +1402,6 @@ expectPrototype.addAdditionalPromiseMethods = function (
1416
1402
} else {
1417
1403
return expect . addAdditionalPromiseMethods (
1418
1404
this . then ( execute ) ,
1419
- expect ,
1420
1405
subject
1421
1406
) ;
1422
1407
}
@@ -1441,9 +1426,8 @@ expectPrototype._createWrappedExpect = function (
1441
1426
if ( arguments . length === 0 ) {
1442
1427
throw new Error ( 'The expect function requires at least one parameter.' ) ;
1443
1428
} else if ( arguments . length === 1 ) {
1444
- return wrappedExpect . addAdditionalPromiseMethods (
1429
+ return parentExpect . addAdditionalPromiseMethods (
1445
1430
makePromise . resolve ( subject ) ,
1446
- wrappedExpect ,
1447
1431
subject
1448
1432
) ;
1449
1433
} else if ( typeof testDescriptionString === 'function' ) {
@@ -1597,13 +1581,9 @@ expectPrototype._executeExpect = function (
1597
1581
} else {
1598
1582
result = makePromise . resolve ( result ) ;
1599
1583
}
1600
- // Her mangler vi wrappedExpect?
1601
1584
return wrappedExpect . addAdditionalPromiseMethods (
1602
1585
result ,
1603
- this ,
1604
1586
subject ,
1605
- Array . prototype . slice . call ( args , 0 , 2 ) ,
1606
- wrappedExpect
1607
1587
) ;
1608
1588
} ;
1609
1589
@@ -1936,7 +1916,7 @@ expectPrototype._callInNestedContext = function (callback) {
1936
1916
} else {
1937
1917
result = makePromise . resolve ( result ) ;
1938
1918
}
1939
- return this . addAdditionalPromiseMethods ( result , this . execute , this . subject ) ;
1919
+ return this . addAdditionalPromiseMethods ( result , this . subject ) ;
1940
1920
} catch ( e ) {
1941
1921
if ( e && e . _isUnexpected ) {
1942
1922
const wrappedError = new UnexpectedError ( this , e ) ;
0 commit comments