@@ -247,27 +247,25 @@ function createExpectIt(expect, expectations, forwardedFlags) {
247247
248248 const camelCaseMethods = expect . _camelCaser ( expect . context || new Context ( ) ) ;
249249 Object . keys ( camelCaseMethods ) . forEach ( ( methodName ) => {
250- expectIt [
251- `and${ methodName . replace ( / ^ [ a - z ] / , ( $0 ) => $0 . toUpperCase ( ) ) } `
252- ] = function ( ...args ) {
253- const copiedExpectations = expectations . slice ( ) ;
254- copiedExpectations . push ( [
255- methodName . replace ( / [ A - Z ] / g, ( $0 ) => ` ${ $0 . toLowerCase ( ) } ` ) , // Eeeeek, fix this
256- ...args ,
257- ] ) ;
258- return createExpectIt ( expect , copiedExpectations , forwardedFlags ) ;
259- } ;
250+ expectIt [ `and${ methodName . replace ( / ^ [ a - z ] / , ( $0 ) => $0 . toUpperCase ( ) ) } ` ] =
251+ function ( ...args ) {
252+ const copiedExpectations = expectations . slice ( ) ;
253+ copiedExpectations . push ( [
254+ methodName . replace ( / [ A - Z ] / g, ( $0 ) => ` ${ $0 . toLowerCase ( ) } ` ) , // Eeeeek, fix this
255+ ...args ,
256+ ] ) ;
257+ return createExpectIt ( expect , copiedExpectations , forwardedFlags ) ;
258+ } ;
260259
261- expectIt [
262- `or${ methodName . replace ( / ^ [ a - z ] / , ( $0 ) => $0 . toUpperCase ( ) ) } `
263- ] = function ( ...args ) {
264- const copiedExpectations = expectations . slice ( ) ;
265- copiedExpectations . push ( OR , [
266- methodName . replace ( / [ A - Z ] / g, ( $0 ) => ` ${ $0 . toLowerCase ( ) } ` ) , // Eeeeek, fix this
267- ...args ,
268- ] ) ;
269- return createExpectIt ( expect , copiedExpectations , forwardedFlags ) ;
270- } ;
260+ expectIt [ `or${ methodName . replace ( / ^ [ a - z ] / , ( $0 ) => $0 . toUpperCase ( ) ) } ` ] =
261+ function ( ...args ) {
262+ const copiedExpectations = expectations . slice ( ) ;
263+ copiedExpectations . push ( OR , [
264+ methodName . replace ( / [ A - Z ] / g, ( $0 ) => ` ${ $0 . toLowerCase ( ) } ` ) , // Eeeeek, fix this
265+ ...args ,
266+ ] ) ;
267+ return createExpectIt ( expect , copiedExpectations , forwardedFlags ) ;
268+ } ;
271269 } ) ;
272270
273271 return expectIt ;
@@ -1358,14 +1356,15 @@ expectPrototype._createWrappedExpect = function (
13581356 for ( let i = 2 ; i < arguments . length ; i += 1 ) {
13591357 args [ i - 2 ] = arguments [ i ] ;
13601358 }
1361- return wrappedExpect . _callInNestedContext ( ( ) =>
1362- parentExpect . _executeExpect (
1363- context . child ( ) ,
1364- subject ,
1365- testDescriptionString ,
1366- args ,
1367- wrappedExpect . flags
1368- )
1359+ return wrappedExpect . _callInNestedContext (
1360+ ( ) =>
1361+ parentExpect . _executeExpect (
1362+ context . child ( ) ,
1363+ subject ,
1364+ testDescriptionString ,
1365+ args ,
1366+ wrappedExpect . flags
1367+ ) . result
13691368 ) ;
13701369 }
13711370
@@ -1476,7 +1475,10 @@ expectPrototype._executeExpect = function (
14761475 forwardedFlags
14771476 ) ;
14781477
1479- return oathbreaker ( assertionRule . handler ( wrappedExpect , subject , ...args ) ) ;
1478+ return {
1479+ result : oathbreaker ( assertionRule . handler ( wrappedExpect , subject , ...args ) ) ,
1480+ wrappedExpect,
1481+ } ;
14801482} ;
14811483
14821484expectPrototype . _camelCaser = function ( context , subjectType , subject ) {
@@ -1490,13 +1492,15 @@ expectPrototype._camelCaser = function (context, subjectType, subject) {
14901492 subjectType . is ( assertion . subject . type )
14911493 )
14921494 ) {
1493- let method = ( subject ) => ( ...args ) => {
1494- return this . _expect ( context , [
1495- subject ,
1496- testDescriptionString ,
1497- ...args ,
1498- ] ) ;
1499- } ;
1495+ let method =
1496+ ( subject ) =>
1497+ ( ...args ) => {
1498+ return this . _expect ( context , [
1499+ subject ,
1500+ testDescriptionString ,
1501+ ...args ,
1502+ ] ) ;
1503+ } ;
15001504
15011505 if ( subjectType ) {
15021506 method = method ( subject ) ;
@@ -1532,7 +1536,7 @@ expectPrototype._expect = function (context, args, forwardedFlags) {
15321536 }
15331537
15341538 try {
1535- let result = this . _executeExpect (
1539+ let { result, wrappedExpect } = this . _executeExpect (
15361540 context ,
15371541 subject ,
15381542 testDescriptionString ,
@@ -1557,7 +1561,8 @@ expectPrototype._expect = function (context, args, forwardedFlags) {
15571561 result ,
15581562 this ,
15591563 subject ,
1560- Array . prototype . slice . call ( args , 0 , 2 )
1564+ Array . prototype . slice . call ( args , 0 , 2 ) ,
1565+ wrappedExpect
15611566 ) ;
15621567 } catch ( e ) {
15631568 if ( e && e . _isUnexpected ) {
@@ -1837,6 +1842,53 @@ expectPrototype._callInNestedContext = function (callback) {
18371842 }
18381843} ;
18391844
1845+ expectPrototype . shifty = function ( subject , args , rest ) {
1846+ this . _assertWrappedExpect ( ) ;
1847+
1848+ const nextArgumentType = this . findTypeOf ( rest [ 0 ] ) ;
1849+ if ( arguments . length > 1 ) {
1850+ // Legacy
1851+ this . argsOutput = ( output ) => {
1852+ args . forEach ( ( arg , index ) => {
1853+ if ( index > 0 ) {
1854+ output . text ( ', ' ) ;
1855+ }
1856+ output . appendInspected ( arg ) ;
1857+ } ) ;
1858+
1859+ if ( args . length > 0 ) {
1860+ output . sp ( ) ;
1861+ }
1862+ if ( nextArgumentType . is ( 'string' ) ) {
1863+ output . error ( rest [ 0 ] ) ;
1864+ } else if ( rest . length > 0 ) {
1865+ output . appendInspected ( rest [ 0 ] ) ;
1866+ }
1867+ if ( rest . length > 1 ) {
1868+ output . sp ( ) ;
1869+ }
1870+ rest . slice ( 1 ) . forEach ( ( arg , index ) => {
1871+ if ( index > 0 ) {
1872+ output . text ( ', ' ) ;
1873+ }
1874+ output . appendInspected ( arg ) ;
1875+ } ) ;
1876+ } ;
1877+ }
1878+ if ( nextArgumentType . is ( 'expect.it' ) ) {
1879+ return this . withError (
1880+ ( ) => rest [ 0 ] ( subject ) ,
1881+ ( err ) => {
1882+ this . fail ( err ) ;
1883+ }
1884+ ) ;
1885+ } else if ( nextArgumentType . is ( 'string' ) ) {
1886+ return this . execute ( subject , ...rest ) ;
1887+ } else {
1888+ return subject ;
1889+ }
1890+ } ;
1891+
18401892expectPrototype . shift = function ( subject , assertionIndex ) {
18411893 this . _assertWrappedExpect ( ) ;
18421894 if ( arguments . length <= 1 ) {
@@ -1860,48 +1912,7 @@ expectPrototype.shift = function (subject, assertionIndex) {
18601912 if ( assertionIndex !== - 1 ) {
18611913 const args = this . args . slice ( 0 , assertionIndex ) ;
18621914 const rest = this . args . slice ( assertionIndex ) ;
1863- const nextArgumentType = this . findTypeOf ( rest [ 0 ] ) ;
1864- if ( arguments . length > 1 ) {
1865- // Legacy
1866- this . argsOutput = ( output ) => {
1867- args . forEach ( ( arg , index ) => {
1868- if ( index > 0 ) {
1869- output . text ( ', ' ) ;
1870- }
1871- output . appendInspected ( arg ) ;
1872- } ) ;
1873-
1874- if ( args . length > 0 ) {
1875- output . sp ( ) ;
1876- }
1877- if ( nextArgumentType . is ( 'string' ) ) {
1878- output . error ( rest [ 0 ] ) ;
1879- } else if ( rest . length > 0 ) {
1880- output . appendInspected ( rest [ 0 ] ) ;
1881- }
1882- if ( rest . length > 1 ) {
1883- output . sp ( ) ;
1884- }
1885- rest . slice ( 1 ) . forEach ( ( arg , index ) => {
1886- if ( index > 0 ) {
1887- output . text ( ', ' ) ;
1888- }
1889- output . appendInspected ( arg ) ;
1890- } ) ;
1891- } ;
1892- }
1893- if ( nextArgumentType . is ( 'expect.it' ) ) {
1894- return this . withError (
1895- ( ) => rest [ 0 ] ( subject ) ,
1896- ( err ) => {
1897- this . fail ( err ) ;
1898- }
1899- ) ;
1900- } else if ( nextArgumentType . is ( 'string' ) ) {
1901- return this . execute ( subject , ...rest ) ;
1902- } else {
1903- return subject ;
1904- }
1915+ return this . shifty ( subject , args , rest ) ;
19051916 } else {
19061917 // No assertion to delegate to. Provide the new subject as the fulfillment value:
19071918 return subject ;
0 commit comments