@@ -244,6 +244,32 @@ function createExpectIt(expect, expectations, forwardedFlags) {
244244 copiedExpectations . push ( OR , args ) ;
245245 return createExpectIt ( expect , copiedExpectations , forwardedFlags ) ;
246246 } ;
247+
248+ const camelCaseMethods = expect . _camelCaser ( expect . context || new Context ( ) ) ;
249+ 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+ } ;
260+
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+ } ;
271+ } ) ;
272+
247273 return expectIt ;
248274}
249275
@@ -714,7 +740,7 @@ expectPrototype.addAssertion = function (
714740 ] = ( ...args ) =>
715741 createExpectIt (
716742 this . _topLevelExpect ,
717- [ [ testDescriptionString , ...args ] ] ,
743+ [ [ handler . testDescriptionString , ...args ] ] ,
718744 this . flags
719745 ) ;
720746
@@ -1312,7 +1338,11 @@ expectPrototype._createWrappedExpect = function (
13121338 if ( arguments . length === 0 ) {
13131339 throw new Error ( 'The expect function requires at least one parameter.' ) ;
13141340 } else if ( arguments . length === 1 ) {
1315- return parentExpect . _camelCaser ( subject , context ) ;
1341+ return parentExpect . _camelCaser (
1342+ context ,
1343+ parentExpect . findTypeOf ( subject ) ,
1344+ subject
1345+ ) ;
13161346 } else if ( typeof testDescriptionString === 'function' ) {
13171347 wrappedExpect . errorMode = 'nested' ;
13181348 return wrappedExpect . withError (
@@ -1449,28 +1479,34 @@ expectPrototype._executeExpect = function (
14491479 return oathbreaker ( assertionRule . handler ( wrappedExpect , subject , ...args ) ) ;
14501480} ;
14511481
1452- expectPrototype . _camelCaser = function ( subject , context ) {
1453- const subjectType = this . findTypeOf ( subject ) ;
1482+ expectPrototype . _camelCaser = function ( context , subjectType , subject ) {
14541483 const methods = { } ;
14551484 let instance = this ;
14561485 while ( instance ) {
14571486 Object . keys ( instance . assertions ) . forEach ( ( testDescriptionString ) => {
14581487 if (
1488+ ! subjectType ||
14591489 instance . assertions [ testDescriptionString ] . some ( ( assertion ) =>
14601490 subjectType . is ( assertion . subject . type )
14611491 )
14621492 ) {
1463- methods [
1464- testDescriptionString . replace ( / [ a - z ] / g, ( $0 ) =>
1465- $0 . charAt ( 1 ) . toUpperCase ( )
1466- )
1467- ] = ( ...args ) => {
1493+ let method = ( subject ) => ( ...args ) => {
14681494 return this . _expect ( context , [
14691495 subject ,
14701496 testDescriptionString ,
14711497 ...args ,
14721498 ] ) ;
14731499 } ;
1500+
1501+ if ( subjectType ) {
1502+ method = method ( subject ) ;
1503+ }
1504+
1505+ methods [
1506+ testDescriptionString . replace ( / [ a - z ] / g, ( $0 ) =>
1507+ $0 . charAt ( 1 ) . toUpperCase ( )
1508+ )
1509+ ] = method ;
14741510 }
14751511 } ) ;
14761512 instance = instance . parent ;
@@ -1485,7 +1521,7 @@ expectPrototype._expect = function (context, args, forwardedFlags) {
14851521 if ( args . length < 1 ) {
14861522 throw new Error ( 'The expect function requires at least one parameter.' ) ;
14871523 } else if ( args . length === 1 ) {
1488- return this . _camelCaser ( subject , context ) ;
1524+ return this . _camelCaser ( context , this . findTypeOf ( subject ) , subject ) ;
14891525 } else if ( typeof testDescriptionString === 'function' ) {
14901526 return this . withError (
14911527 ( ) => testDescriptionString ( subject ) ,
0 commit comments