@@ -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
@@ -730,7 +756,7 @@ expectPrototype.addAssertion = function (
730756 ] = ( ...args ) =>
731757 createExpectIt (
732758 this . _topLevelExpect ,
733- [ [ testDescriptionString , ...args ] ] ,
759+ [ [ handler . testDescriptionString , ...args ] ] ,
734760 this . flags
735761 ) ;
736762
@@ -1323,7 +1349,11 @@ expectPrototype._createWrappedExpect = function (
13231349 if ( arguments . length === 0 ) {
13241350 throw new Error ( 'The expect function requires at least one parameter.' ) ;
13251351 } else if ( arguments . length === 1 ) {
1326- return parentExpect . _camelCaser ( subject , context ) ;
1352+ return parentExpect . _camelCaser (
1353+ context ,
1354+ parentExpect . findTypeOf ( subject ) ,
1355+ subject
1356+ ) ;
13271357 } else if ( typeof testDescriptionString === 'function' ) {
13281358 wrappedExpect . errorMode = 'nested' ;
13291359 return wrappedExpect . withError (
@@ -1460,28 +1490,34 @@ expectPrototype._executeExpect = function (
14601490 return oathbreaker ( assertionRule . handler ( wrappedExpect , subject , ...args ) ) ;
14611491} ;
14621492
1463- expectPrototype . _camelCaser = function ( subject , context ) {
1464- const subjectType = this . findTypeOf ( subject ) ;
1493+ expectPrototype . _camelCaser = function ( context , subjectType , subject ) {
14651494 const methods = { } ;
14661495 let instance = this ;
14671496 while ( instance ) {
14681497 Object . keys ( instance . assertions ) . forEach ( ( testDescriptionString ) => {
14691498 if (
1499+ ! subjectType ||
14701500 instance . assertions [ testDescriptionString ] . some ( ( assertion ) =>
14711501 subjectType . is ( assertion . subject . type )
14721502 )
14731503 ) {
1474- methods [
1475- testDescriptionString . replace ( / [ a - z ] / g, ( $0 ) =>
1476- $0 . charAt ( 1 ) . toUpperCase ( )
1477- )
1478- ] = ( ...args ) => {
1504+ let method = ( subject ) => ( ...args ) => {
14791505 return this . _expect ( context , [
14801506 subject ,
14811507 testDescriptionString ,
14821508 ...args ,
14831509 ] ) ;
14841510 } ;
1511+
1512+ if ( subjectType ) {
1513+ method = method ( subject ) ;
1514+ }
1515+
1516+ methods [
1517+ testDescriptionString . replace ( / [ a - z ] / g, ( $0 ) =>
1518+ $0 . charAt ( 1 ) . toUpperCase ( )
1519+ )
1520+ ] = method ;
14851521 }
14861522 } ) ;
14871523 instance = instance . parent ;
@@ -1496,7 +1532,7 @@ expectPrototype._expect = function (context, args, forwardedFlags) {
14961532 if ( args . length < 1 ) {
14971533 throw new Error ( 'The expect function requires at least one parameter.' ) ;
14981534 } else if ( args . length === 1 ) {
1499- return this . _camelCaser ( subject , context ) ;
1535+ return this . _camelCaser ( context , this . findTypeOf ( subject ) , subject ) ;
15001536 } else if ( typeof testDescriptionString === 'function' ) {
15011537 return this . withError (
15021538 ( ) => testDescriptionString ( subject ) ,
0 commit comments