11/*!
22 * should - test framework agnostic BDD-style assertions
3- * @version v13.0.1
3+ * @version v13.1.0
44 * @author TJ Holowaychuk <tj@vision-media.ca>, Denis Bardadym <bardadymchik@gmail.com>
55 * @link https://github.com/shouldjs/should.js
66 * @license MIT
@@ -1670,6 +1670,12 @@ Assertion.prototype = {
16701670 */
16711671 fail : function ( ) {
16721672 return this . assert ( false ) ;
1673+ } ,
1674+
1675+ assertZeroArguments : function ( args ) {
1676+ if ( args . length !== 0 ) {
1677+ throw new TypeError ( "This assertion does not expect any arguments. You may need to check your code" ) ;
1678+ }
16731679 }
16741680} ;
16751681
@@ -1828,22 +1834,11 @@ Assertion.addChain = function(name, onCall) {
18281834Assertion . alias = function ( from , to ) {
18291835 var desc = Object . getOwnPropertyDescriptor ( Assertion . prototype , from ) ;
18301836 if ( ! desc ) {
1831- throw new Error (
1832- "Alias " +
1833- from +
1834- " -> " +
1835- to +
1836- " could not be created as " +
1837- from +
1838- " not defined"
1839- ) ;
1837+ throw new Error ( "Alias " + from + " -> " + to + " could not be created as " + from + " not defined" ) ;
18401838 }
18411839 Object . defineProperty ( Assertion . prototype , to , desc ) ;
18421840
1843- var desc2 = Object . getOwnPropertyDescriptor (
1844- PromisedAssertion . prototype ,
1845- from
1846- ) ;
1841+ var desc2 = Object . getOwnPropertyDescriptor ( PromisedAssertion . prototype , from ) ;
18471842 if ( desc2 ) {
18481843 Object . defineProperty ( PromisedAssertion . prototype , to , desc2 ) ;
18491844 }
@@ -2355,6 +2350,7 @@ var booleanAssertions = function(should, Assertion) {
23552350 * (0).should.not.be.ok();
23562351 */
23572352 Assertion . add ( "ok" , function ( ) {
2353+ this . assertZeroArguments ( arguments ) ;
23582354 this . params = { operator : "to be truthy" } ;
23592355
23602356 this . assert ( this . obj ) ;
@@ -2380,6 +2376,7 @@ var numberAssertions = function(should, Assertion) {
23802376 * NaN.should.be.NaN();
23812377 */
23822378 Assertion . add ( "NaN" , function ( ) {
2379+ this . assertZeroArguments ( arguments ) ;
23832380 this . params = { operator : "to be NaN" } ;
23842381
23852382 this . assert ( this . obj !== this . obj ) ;
@@ -2397,6 +2394,7 @@ var numberAssertions = function(should, Assertion) {
23972394 * NaN.should.not.be.Infinity();
23982395 */
23992396 Assertion . add ( "Infinity" , function ( ) {
2397+ this . assertZeroArguments ( arguments ) ;
24002398 this . params = { operator : "to be Infinity" } ;
24012399
24022400 this . is . a
@@ -2555,6 +2553,7 @@ var typeAssertions = function(should, Assertion) {
25552553 * @category assertion types
25562554 */
25572555 Assertion . add ( "Number" , function ( ) {
2556+ this . assertZeroArguments ( arguments ) ;
25582557 this . params = { operator : "to be a number" } ;
25592558
25602559 this . have . type ( "number" ) ;
@@ -2568,6 +2567,7 @@ var typeAssertions = function(should, Assertion) {
25682567 * @category assertion types
25692568 */
25702569 Assertion . add ( "arguments" , function ( ) {
2570+ this . assertZeroArguments ( arguments ) ;
25712571 this . params = { operator : "to be arguments" } ;
25722572
25732573 this . have . class ( "Arguments" ) ;
@@ -2616,6 +2616,7 @@ var typeAssertions = function(should, Assertion) {
26162616 * @category assertion types
26172617 */
26182618 Assertion . add ( "Function" , function ( ) {
2619+ this . assertZeroArguments ( arguments ) ;
26192620 this . params = { operator : "to be a function" } ;
26202621
26212622 this . have . type ( "function" ) ;
@@ -2628,6 +2629,7 @@ var typeAssertions = function(should, Assertion) {
26282629 * @category assertion types
26292630 */
26302631 Assertion . add ( "Object" , function ( ) {
2632+ this . assertZeroArguments ( arguments ) ;
26312633 this . params = { operator : "to be an object" } ;
26322634
26332635 this . is . not . null ( ) . and . have . type ( "object" ) ;
@@ -2640,6 +2642,7 @@ var typeAssertions = function(should, Assertion) {
26402642 * @category assertion types
26412643 */
26422644 Assertion . add ( "String" , function ( ) {
2645+ this . assertZeroArguments ( arguments ) ;
26432646 this . params = { operator : "to be a string" } ;
26442647
26452648 this . have . type ( "string" ) ;
@@ -2652,6 +2655,7 @@ var typeAssertions = function(should, Assertion) {
26522655 * @category assertion types
26532656 */
26542657 Assertion . add ( "Array" , function ( ) {
2658+ this . assertZeroArguments ( arguments ) ;
26552659 this . params = { operator : "to be an array" } ;
26562660
26572661 this . have . class ( "Array" ) ;
@@ -2664,6 +2668,7 @@ var typeAssertions = function(should, Assertion) {
26642668 * @category assertion types
26652669 */
26662670 Assertion . add ( "Boolean" , function ( ) {
2671+ this . assertZeroArguments ( arguments ) ;
26672672 this . params = { operator : "to be a boolean" } ;
26682673
26692674 this . have . type ( "boolean" ) ;
@@ -2676,6 +2681,7 @@ var typeAssertions = function(should, Assertion) {
26762681 * @category assertion types
26772682 */
26782683 Assertion . add ( "Error" , function ( ) {
2684+ this . assertZeroArguments ( arguments ) ;
26792685 this . params = { operator : "to be an error" } ;
26802686
26812687 this . have . instanceOf ( Error ) ;
@@ -2688,6 +2694,7 @@ var typeAssertions = function(should, Assertion) {
26882694 * @category assertion types
26892695 */
26902696 Assertion . add ( "Date" , function ( ) {
2697+ this . assertZeroArguments ( arguments ) ;
26912698 this . params = { operator : "to be a date" } ;
26922699
26932700 this . have . instanceOf ( Date ) ;
@@ -2701,6 +2708,7 @@ var typeAssertions = function(should, Assertion) {
27012708 * @category assertion types
27022709 */
27032710 Assertion . add ( "null" , function ( ) {
2711+ this . assertZeroArguments ( arguments ) ;
27042712 this . params = { operator : "to be null" } ;
27052713
27062714 this . assert ( this . obj === null ) ;
@@ -2718,9 +2726,7 @@ var typeAssertions = function(should, Assertion) {
27182726 Assertion . add ( "class" , function ( cls ) {
27192727 this . params = { operator : "to have [[Class]] " + cls } ;
27202728
2721- this . assert (
2722- Object . prototype . toString . call ( this . obj ) === "[object " + cls + "]"
2723- ) ;
2729+ this . assert ( Object . prototype . toString . call ( this . obj ) === "[object " + cls + "]" ) ;
27242730 } ) ;
27252731
27262732 Assertion . alias ( "class" , "Class" ) ;
@@ -2733,6 +2739,7 @@ var typeAssertions = function(should, Assertion) {
27332739 * @category assertion types
27342740 */
27352741 Assertion . add ( "undefined" , function ( ) {
2742+ this . assertZeroArguments ( arguments ) ;
27362743 this . params = { operator : "to be undefined" } ;
27372744
27382745 this . assert ( this . obj === void 0 ) ;
@@ -2748,6 +2755,7 @@ var typeAssertions = function(should, Assertion) {
27482755 * @category assertion es6
27492756 */
27502757 Assertion . add ( "iterable" , function ( ) {
2758+ this . assertZeroArguments ( arguments ) ;
27512759 this . params = { operator : "to be iterable" } ;
27522760
27532761 should ( this . obj )
@@ -2763,6 +2771,7 @@ var typeAssertions = function(should, Assertion) {
27632771 * @category assertion es6
27642772 */
27652773 Assertion . add ( "iterator" , function ( ) {
2774+ this . assertZeroArguments ( arguments ) ;
27662775 this . params = { operator : "to be iterator" } ;
27672776
27682777 should ( this . obj )
@@ -2777,11 +2786,10 @@ var typeAssertions = function(should, Assertion) {
27772786 * @category assertion es6
27782787 */
27792788 Assertion . add ( "generator" , function ( ) {
2789+ this . assertZeroArguments ( arguments ) ;
27802790 this . params = { operator : "to be generator" } ;
27812791
2782- should ( this . obj ) . be . iterable . and . iterator . and . it . is . equal (
2783- this . obj [ Symbol . iterator ] ( )
2784- ) ;
2792+ should ( this . obj ) . be . iterable . and . iterator . and . it . is . equal ( this . obj [ Symbol . iterator ] ( ) ) ;
27852793 } ) ;
27862794} ;
27872795
@@ -2948,6 +2956,7 @@ var promiseAssertions = function(should, Assertion$$1) {
29482956 * (10).should.not.be.a.Promise()
29492957 */
29502958 Assertion$$1 . add ( "Promise" , function ( ) {
2959+ this . assertZeroArguments ( arguments ) ;
29512960 this . params = { operator : "to be promise" } ;
29522961
29532962 var obj = this . obj ;
@@ -2962,6 +2971,7 @@ var promiseAssertions = function(should, Assertion$$1) {
29622971 *
29632972 * @name fulfilled
29642973 * @memberOf Assertion
2974+ * @alias Assertion#resolved
29652975 * @returns {Promise }
29662976 * @category assertion promises
29672977 * @example
@@ -2976,6 +2986,7 @@ var promiseAssertions = function(should, Assertion$$1) {
29762986 * });
29772987 */
29782988 Assertion$$1 . prototype . fulfilled = function Assertion$fulfilled ( ) {
2989+ this . assertZeroArguments ( arguments ) ;
29792990 this . params = { operator : "to be fulfilled" } ;
29802991
29812992 should ( this . obj ) . be . a . Promise ( ) ;
@@ -2990,15 +3001,16 @@ var promiseAssertions = function(should, Assertion$$1) {
29903001 } ,
29913002 function next$onReject ( err ) {
29923003 if ( ! that . negate ) {
2993- that . params . operator +=
2994- ", but it was rejected with " + should . format ( err ) ;
3004+ that . params . operator += ", but it was rejected with " + should . format ( err ) ;
29953005 that . fail ( ) ;
29963006 }
29973007 return err ;
29983008 }
29993009 ) ;
30003010 } ;
30013011
3012+ Assertion$$1 . prototype . resolved = Assertion$$1 . prototype . fulfilled ;
3013+
30023014 /**
30033015 * Assert given promise will be rejected. Result of assertion is still .thenable and should be handled accordingly.
30043016 *
@@ -3019,6 +3031,7 @@ var promiseAssertions = function(should, Assertion$$1) {
30193031 * });
30203032 */
30213033 Assertion$$1 . prototype . rejected = function ( ) {
3034+ this . assertZeroArguments ( arguments ) ;
30223035 this . params = { operator : "to be rejected" } ;
30233036
30243037 should ( this . obj ) . be . a . Promise ( ) ;
@@ -3050,6 +3063,7 @@ var promiseAssertions = function(should, Assertion$$1) {
30503063 *
30513064 * @name fulfilledWith
30523065 * @memberOf Assertion
3066+ * @alias Assertion#resolvedWith
30533067 * @category assertion promises
30543068 * @returns {Promise }
30553069 * @example
@@ -3082,15 +3096,16 @@ var promiseAssertions = function(should, Assertion$$1) {
30823096 } ,
30833097 function next$onError ( err ) {
30843098 if ( ! that . negate ) {
3085- that . params . operator +=
3086- ", but it was rejected with " + should . format ( err ) ;
3099+ that . params . operator += ", but it was rejected with " + should . format ( err ) ;
30873100 that . fail ( ) ;
30883101 }
30893102 return err ;
30903103 }
30913104 ) ;
30923105 } ;
30933106
3107+ Assertion$$1 . prototype . resolvedWith = Assertion$$1 . prototype . fulfilledWith ;
3108+
30943109 /**
30953110 * Assert given promise will be rejected with some sort of error. Arguments is the same for Assertion#throw.
30963111 * Result of assertion is still .thenable and should be handled accordingly.
@@ -3159,18 +3174,9 @@ var promiseAssertions = function(should, Assertion$$1) {
31593174
31603175 if ( ! errorMatched ) {
31613176 if ( typeof message === "string" || message instanceof RegExp ) {
3162- errorInfo =
3163- " with a message matching " +
3164- should . format ( message ) +
3165- ", but got '" +
3166- err . message +
3167- "'" ;
3177+ errorInfo = " with a message matching " + should . format ( message ) + ", but got '" + err . message + "'" ;
31683178 } else if ( "function" === typeof message ) {
3169- errorInfo =
3170- " of type " +
3171- functionName$1 ( message ) +
3172- ", but got " +
3173- functionName$1 ( err . constructor ) ;
3179+ errorInfo = " of type " + functionName$1 ( message ) + ", but got " + functionName$1 ( err . constructor ) ;
31743180 }
31753181 } else if ( "function" === typeof message && properties ) {
31763182 try {
0 commit comments