Comparing version 3.1.2 to 3.1.3
@@ -0,1 +1,6 @@ | ||
3.1.3 / 2014-02-25 | ||
================== | ||
* Fix TypeError in .containEql | ||
3.1.2 / 2014-01-28 | ||
@@ -14,3 +19,3 @@ ================== | ||
* Added jquery based broser extension | ||
* Added jquery based browser extension | ||
@@ -17,0 +22,0 @@ 3.0.1 / 2014-01-17 |
@@ -12,5 +12,8 @@ /*! | ||
Assertion.add('header', function(field, val) { | ||
this | ||
.have.property('headers') | ||
.and.have.property(field.toLowerCase(), val); | ||
this.have.property('headers'); | ||
if (val !== undefined) { | ||
this.have.property(field.toLowerCase(), val); | ||
} else { | ||
this.have.property(field.toLowerCase()); | ||
} | ||
}); | ||
@@ -17,0 +20,0 @@ |
@@ -11,4 +11,3 @@ /*! | ||
this.is.a.Number | ||
.and.assert(isNaN(this.obj)); | ||
this.assert(this.obj !== this.obj); | ||
}, true); | ||
@@ -51,2 +50,2 @@ | ||
}; | ||
}; |
@@ -169,3 +169,3 @@ /*! | ||
util.forOwn(other, function(value, key) { | ||
obj[key].should.eql(value); | ||
obj.should.have.property(key, value); | ||
}); | ||
@@ -172,0 +172,0 @@ } else { |
@@ -1,16 +0,30 @@ | ||
{ "name": "should" | ||
, "description": "test framework agnostic BDD-style assertions" | ||
, "version": "3.1.2" | ||
, "author": "TJ Holowaychuk <tj@vision-media.ca>" | ||
, "repository": { "type": "git", "url": "git://github.com/visionmedia/should.js.git" } | ||
, "homepage": "https://github.com/visionmedia/should.js" | ||
, "scripts": { "test": "make test" } | ||
, "devDependencies": { | ||
"mocha": "*", | ||
"jsdom": "*", | ||
"jquery": "*" | ||
{ | ||
"name": "should", | ||
"description": "test framework agnostic BDD-style assertions", | ||
"version": "3.1.3", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/visionmedia/should.js.git" | ||
}, | ||
"homepage": "https://github.com/visionmedia/should.js", | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"devDependencies": { | ||
"browserify": "*", | ||
"mocha": "*", | ||
"jsdom": "*", | ||
"jquery": "*", | ||
"mocha-better-spec-reporter": "0.0.2" | ||
}, | ||
"keywords": [ | ||
"test", | ||
"bdd", | ||
"assert" | ||
], | ||
"main": "./lib/node.js", | ||
"engines": { | ||
"node": ">= 0.2.0" | ||
} | ||
, "keywords": ["test", "bdd", "assert"] | ||
, "main": "./lib/node.js" | ||
, "engines": { "node": ">= 0.2.0" } | ||
} |
113
Readme.md
# should.js | ||
_should_ is an expressive, readable, test framework agnostic, assertion library. Main goals of this library __to be expressive__ and __to be helpful__. It means test code should be clean, and error messages enough helpfull to understand error. | ||
_should_ is an expressive, readable, test framework agnostic, assertion library. Main goals of this library __to be expressive__ and __to be helpful__. It keeps your test code clean, and your error messages helpful. | ||
@@ -36,23 +36,25 @@ It extends the `Object.prototype` with a single non-enumerable getter that allows you to express how that object should behave, also it returns itself when required with `require`. | ||
```bash | ||
$ npm install should --save-dev | ||
``` | ||
2. Require it and use: | ||
```javascript | ||
var should = require('should'); | ||
```js | ||
var should = require('should'); | ||
(5).should.be.exactly(5).and.be.a.Number; | ||
``` | ||
(5).should.be.exactly(5).and.be.a.Number; | ||
``` | ||
## In browser | ||
If you want to use _should_ in browser, use version that is in root of repository (or build it yourself). It is builded with browserify (see [Makefile](https://github.com/visionmedia/should.js/blob/master/Makefile)). To build fresh version: | ||
If you want to use _should_ in browser, use the `should.js` file in the root of this repository, or build it yourself. It is built with browserify (see [Makefile](https://github.com/visionmedia/should.js/blob/master/Makefile)). To build a fresh version: | ||
```bash | ||
# you should have browserify | ||
npm install -g browserify | ||
make browser | ||
$ npm install -g browserify | ||
$ make browser | ||
``` | ||
This script exported to `window.Should`. It is the same as use `should` statically: | ||
The script is exported to `window.Should`. It is the same as using `should` statically: | ||
@@ -63,3 +65,3 @@ ```js | ||
Also as for node.js case `Object.prototype` extended with `should` (that is why `window.Should` used): | ||
Also, in the case of node.js, `Object.prototype` is extended with `should` (hence the capital S in `window.Should`): | ||
@@ -79,3 +81,3 @@ ```js | ||
You can easy install it with again npm or bower: | ||
You can easy install it with npm or bower: | ||
``` | ||
@@ -90,3 +92,3 @@ npm install should --save-dev | ||
For some rare cases should can be used statically, without `Object.prototype`. | ||
It can be replacement for node assert module: | ||
It can be a replacement for the node assert module: | ||
@@ -106,3 +108,3 @@ ```javascript | ||
``` | ||
## .not | ||
@@ -116,3 +118,3 @@ | ||
Every assertion will return a `should.js`-wrapped Object, so assertions can be chained. | ||
You can use this helpers to just chain: `.an`, `.of`, `.a`, `.and`, `.be`, `.have`, `.with`, `.is`, `.which`. Use them for better readability, they do nothing at all. | ||
To help chained assertions read more clearly, you can use the following helpers anywhere in your chain: `.an`, `.of`, `.a`, `.and`, `.be`, `.have`, `.with`, `.is`, `.which`. Use them for better readability; they do nothing at all. | ||
For example: | ||
@@ -123,7 +125,7 @@ ```js | ||
``` | ||
Almost all assertions return the same object - so you can easy chain them. But some move assertion object to property value. See feather, it will be mention if object chainged. | ||
Almost all assertions return the same object - so you can easy chain them. But some (eg: `.length` and `.property`) move the assertion object to a property value, so be careful. | ||
## .ok | ||
Assert if asseted object is truthy in javascript meaning of truthy ('', null, undefined, 0 , NaN, Infinity - is falsy, so all others are truthy). | ||
Assert if chained object is truthy in javascript (ie: not '', null, undefined, 0 , NaN). | ||
@@ -147,5 +149,12 @@ Assert truthfulness: | ||
*Warning:* No assertions can be done on null and undefined. | ||
e.g. | ||
```js | ||
undefined.should.not.be.ok; | ||
``` | ||
will give you `Uncaught TypeError: Cannot read property 'should' of undefined)`. | ||
## .true | ||
Assert if asseted object === true: | ||
Assert if chained object === true: | ||
@@ -159,3 +168,3 @@ ```javascript | ||
Assert if asseted object === false: | ||
Assert if chained object === false: | ||
@@ -169,3 +178,3 @@ ```javascript | ||
Assert if asserted object is *equal* to otherValue. This means that object compared by its actual content, not just reference equality. | ||
Assert if chained object is *equal* to otherValue. The object is compared by its actual content, not just reference equality. | ||
@@ -180,3 +189,3 @@ ```javascript | ||
Assert if asserted object strictly equal to `otherValue` (using `===` - no type conversion for primitive types and reference equivalence for reference types). | ||
Assert if chained object is strictly equal to `otherValue` (using `===` - no type conversion for primitive types and reference equivalence for reference types). | ||
@@ -192,3 +201,3 @@ ```javascript | ||
Assert that string starts with `str`. | ||
Assert that a string starts with `str`. | ||
@@ -201,3 +210,3 @@ ```javascript | ||
Assert that string ends with `str`. | ||
Assert that a string ends with `str`. | ||
@@ -265,3 +274,3 @@ ```javascript | ||
Assert given value have such type (using __typeof__ operator): | ||
Assert given object is of a particular type (using __typeof__ operator): | ||
```javascript | ||
@@ -274,3 +283,3 @@ user.should.be.type('object'); | ||
Assert given value is instance of `constructor` (using __instanceof__ operator): | ||
Assert given object is an instance of `constructor` (using __instanceof__ operator): | ||
@@ -294,3 +303,3 @@ ```javascript | ||
Assert given object is instance of such constructor (shortcut for `.instanceof` assertion). | ||
Assert given object is instance of the given constructor (shortcut for `.instanceof` assertion). | ||
@@ -307,3 +316,3 @@ ```javascript | ||
Assert property exists and has optional value(compare using `.eql`): | ||
Assert property exists and has optional value (compare using `.eql`): | ||
```javascript | ||
@@ -317,9 +326,9 @@ user.should.have.property('name'); | ||
__NB__ `.property` change object to actual property value! | ||
__NB__ `.property` changes the chain's object to the given property's value, so be careful when chaining after `.property`! | ||
## .properties(propName1, propName2, ...) or .properties([propName1, propName2, ...]) or .properties(obj) | ||
`obj` it is object that map properties to their actual values. | ||
`obj` should be an object that maps properties to their actual values. | ||
Assert all given properties exists and have given values (compare using `.eql`): | ||
Assert all given properties exist and have given values (compare using `.eql`): | ||
@@ -344,3 +353,3 @@ ```javascript | ||
__NB__ `.length` change object to actual property value! | ||
__NB__ `.length` and `.lengthOf` change the chain's object to the given length value, so be careful when chaining! | ||
@@ -354,7 +363,7 @@ ## .ownProperty(str) and .hasOwnProperty(str) | ||
__NB__ `.length` change object to actual property value! | ||
__NB__ `.ownProperty` and `.hasOwnProperty` change the chain's object to the given property value, so be careful when chaining! | ||
## .empty | ||
Assert given value is empty. It means for strings, arrays, arguments length == 0 and for object do not have own properties. | ||
Assert given value is empty. Strings, arrays, arguments with a length of 0, and objects without their own properties, are considered empty. | ||
@@ -424,11 +433,11 @@ ```javascript | ||
It does not search somewhere in depth it check all pattern in depth. Object checked | ||
by properties key and value, arrays checked like sub sequences. Everyting compared using .eql. | ||
Main difference with `.containEql` is that this assertion require full type chain - | ||
It does not search somewhere in depth it check all pattern in depth. Objects are checked | ||
by properties key and value; arrays are checked like sub sequences. Everyting is compared using `.eql`. | ||
Main difference with `.containEql` is that this assertion requires full type chain - | ||
if asserted value is an object, otherValue should be also an object (which is sub object of given). | ||
The same true for arrays, otherValue should be an array which compared to be subsequence of given object. | ||
The same is true for arrays, otherValue should be an array which compared to be subsequence of given object. | ||
## .match(otherValue) | ||
Assert given object to match `otherValue`. | ||
Assert given object matches `otherValue`. | ||
@@ -454,3 +463,3 @@ Given: String, otherValue: regexp. Uses `RegExp#exec(str)`: | ||
Function can use .should inside or return 'true' or 'false', in all other cases it do nothing. If you return value that return assertion, you will receive better error messages. | ||
Function can use `.should` inside or return 'true' or 'false', in all other cases it do nothing. If you return value that return assertion, you will receive better error messages. | ||
@@ -501,3 +510,3 @@ ```javascript | ||
In other cases it check that each property value is `.eql` to `otherValue`: | ||
In other cases it checks that each property value is `.eql` to `otherValue`: | ||
```javascript | ||
@@ -549,3 +558,3 @@ [10, 10].should.matchEach(10); | ||
If you need to check something in asynchronous function it is required to do in 2 steps: | ||
If you need to check something in an asynchronous function, you must do it in 2 steps: | ||
@@ -565,3 +574,3 @@ ```js | ||
In case you are using something like `Mocha`, you should use asynchronous test and call `done()` in proper place to make sure that you asynchronous function is called before test is finished. | ||
In case you are using something like `Mocha`, you should use an asynchronous test, and call `done()` in the proper place to make sure that your asynchronous function is called before the test finishes. | ||
```js | ||
@@ -577,3 +586,3 @@ collection.findOne({ _id: 10 }, function(err, res) { | ||
In general case if you need to check that something is executed you need such thing as `spies`, good example is an [sinon](http://sinonjs.org/). | ||
In general, if you need to check that something is executed, you are best using `spies`. A good example is [sinon](http://sinonjs.org/). | ||
@@ -639,6 +648,6 @@ ## .status(code) | ||
describe('mylib', function () { | ||
describe('mylib', function() { | ||
it('should have a version with the format #.#.#', function() { | ||
lib.version.should.match(/^\d+\.\d+\.\d+$/); | ||
} | ||
}); | ||
}); | ||
@@ -657,9 +666,9 @@ ``` | ||
1. Your code looks like all other code - all project should look like it was written by one man, always. | ||
2. If you want propose something - just create issue and describe your question with much description as you can. | ||
3. Please never send issues or pull requests about code style, jshint violations etc - i do not accept it (and you will spend your time for free). | ||
4. If you think you have some general receipt, consider create PR with it. | ||
5. If you not sure if you receipt enough general just create your own plugin for should.js. (see should.use and Assertion.add usage). | ||
6. If you add new code it should be covered by tests, no tests - no code. | ||
7. If you find bug (or at least you think it is a bug), create issue with library version and test case that I can run and see what are you talking about, or at least full steps that I can reproduce it. | ||
1. Your code should look like all the other code - this project should look like it was written by one man, always. | ||
2. If you want propose something - just create an issue and describe your question with as much description as you can. | ||
3. Please never send issues or pull requests about code style, jshint violations etc - I do not accept it (and you will spend your time for free). | ||
4. If you think you have some general improvement, consider creating a pull request with it. | ||
5. If you are not sure whether your improvement is general enough, just create your own plugin for should.js. (see should.use and Assertion.add usage). | ||
6. If you add new code, it should be covered by tests. No tests - no code. | ||
7. If you find bug (or at least you think it is a bug), create an issue with the library version and test case that I can run and see what are you talking about, or at least full steps by which I can reproduce it. | ||
@@ -666,0 +675,0 @@ ## OMG IT EXTENDS OBJECT???!?!@ |
@@ -20,3 +20,3 @@ !function(C){if("object"==typeof exports)module.exports=C();else if("function"==typeof define&&define.amd)define(C);else{var h;"undefined"!=typeof window?h=window:"undefined"!=typeof global?h=global:"undefined"!=typeof self&&(h=self);h.Should=C()}}(function(){return function h(k,d,g){function l(f,c){if(!d[f]){if(!k[f]){var e="function"==typeof require&&require;if(!c&&e)return e(f,!0);if(a)return a(f,!0);throw Error("Cannot find module '"+f+"'");}e=d[f]={exports:{}};k[f][0].call(e.exports,function(b){var c= | ||
"\n\t"+k.message),k;}h instanceof e&&(this.params.operator+="\n\t"+h.getMessage());g.isBoolean(h)&&this.assert(h)}else g.isObject(c)?(b=[],p=[],g.forOwn(c,function(c,f){try{this.obj[f].should.match(c),p.push(f)}catch(e){if(e instanceof a.AssertionError)b.push(f);else throw e;}},this),b.length&&(this.params.operator+="\n\tnot matched properties: "+b.join(", ")),p.length&&(this.params.operator+="\n\tmatched properties: "+p.join(", ")),this.assert(0==b.length)):this.assert(!1)});e.add("matchEach",function(c, | ||
a){this.params={operator:"to match each "+f(c),message:a};var b=c;g.isRegExp(c)?b=function(b){return!!c.exec(b)}:g.isFunction(c)||(b=function(b){return l(b,c)});g.forOwn(this.obj,function(c,a){var f=b(c,a);g.isBoolean(f)&&this.assert(f)},this)})}},{"../eql":2,"../util":16}],11:[function(h,k,d){k.exports=function(g,d){d.add("NaN",function(){this.params={operator:"to be NaN"};this.is.a.Number.and.assert(isNaN(this.obj))},!0);d.add("Infinity",function(){this.params={operator:"to be Infinity"};this.is.a.Number.and.not.a.NaN.and.assert(!isFinite(this.obj))}, | ||
a){this.params={operator:"to match each "+f(c),message:a};var b=c;g.isRegExp(c)?b=function(b){return!!c.exec(b)}:g.isFunction(c)||(b=function(b){return l(b,c)});g.forOwn(this.obj,function(c,a){var f=b(c,a);g.isBoolean(f)&&this.assert(f)},this)})}},{"../eql":2,"../util":16}],11:[function(h,k,d){k.exports=function(g,d){d.add("NaN",function(){this.params={operator:"to be NaN"};this.assert(this.obj!==this.obj)},!0);d.add("Infinity",function(){this.params={operator:"to be Infinity"};this.is.a.Number.and.not.a.NaN.and.assert(!isFinite(this.obj))}, | ||
!0);d.add("within",function(a,e,f){this.params={operator:"to be within "+a+".."+e,message:f};this.assert(this.obj>=a&&this.obj<=e)});d.add("approximately",function(a,e,f){this.params={operator:"to be approximately "+a+" \u00b1"+e,message:f};this.assert(Math.abs(this.obj-a)<=e)});d.add("above",function(a,e){this.params={operator:"to be above "+a,message:e};this.assert(this.obj>a)});d.add("below",function(a,e){this.params={operator:"to be below "+a,message:e};this.assert(this.obj<a)});d.alias("above", | ||
@@ -27,3 +27,3 @@ "greaterThan");d.alias("below","lessThan")}},{}],12:[function(h,k,d){var g=h("../util"),l=h("../eql"),a=Array.prototype.slice;k.exports=function(e,f){var c=e.format;f.add("property",function(b,c){if(1<arguments.length){var a={};a[b]=c;this.have.properties(a)}else this.have.properties(b);this.obj=this.obj[b]});f.add("properties",function(b){var f={};1<arguments.length?b=a.call(arguments):Array.isArray(b)||(g.isString(b)?b=[b]:(f=b,b=Object.keys(b)));var e=Object(this.obj),d=[];b.forEach(function(b){b in | ||
!0);f.add("keys",function(b){1<arguments.length?b=a.call(arguments):1===arguments.length&&g.isString(b)?b=[b]:0===arguments.length&&(b=[]);var f=Object(this.obj),e=[];b.forEach(function(b){d.call(this.obj,b)||e.push(c(b))},this);var h=[];Object.keys(f).forEach(function(a){0>b.indexOf(a)&&h.push(c(a))});this.params={operator:(0===b.length?"to be empty":"to have "+(1===b.length?"key ":"keys "))+b.map(c).join(", ")};0<e.length&&(this.params.operator+="\n\tmissing keys: "+e.join(", "));0<h.length&&(this.params.operator+= | ||
"\n\textra keys: "+h.join(", "));this.assert(0===e.length&&0===h.length)});f.alias("keys","key");f.add("containEql",function(b){this.params={operator:"to contain "+c(b)};var a=this.obj;Array.isArray(a)?this.assert(a.some(function(c){return l(c,b)})):g.isString(a)?this.assert(0<=a.indexOf(String(b))):g.isObject(a)?g.forOwn(b,function(b,c){a[c].should.eql(b)}):this.assert(!1)});f.add("containDeep",function(b){this.params={operator:"to contain "+c(b)};var a=this.obj;if(Array.isArray(a))if(Array.isArray(b)){var f= | ||
"\n\textra keys: "+h.join(", "));this.assert(0===e.length&&0===h.length)});f.alias("keys","key");f.add("containEql",function(b){this.params={operator:"to contain "+c(b)};var a=this.obj;Array.isArray(a)?this.assert(a.some(function(c){return l(c,b)})):g.isString(a)?this.assert(0<=a.indexOf(String(b))):g.isObject(a)?g.forOwn(b,function(b,c){a.should.have.property(c,b)}):this.assert(!1)});f.add("containDeep",function(b){this.params={operator:"to contain "+c(b)};var a=this.obj;if(Array.isArray(a))if(Array.isArray(b)){var f= | ||
0;a.forEach(function(a){try{e(a).not.be.null.and.containDeep(b[f]),f++}catch(c){if(!(c instanceof e.AssertionError))throw c;}});this.assert(f==b.length)}else this.assert(!1);else g.isString(a)?this.assert(0<=a.indexOf(String(b))):g.isObject(a)?g.isObject(b)?g.forOwn(b,function(b,c){e(a[c]).not.be.null.and.containDeep(b)}):this.assert(!1):this.eql(b)})}},{"../eql":2,"../util":16}],13:[function(h,k,d){k.exports=function(d,h){h.add("startWith",function(a,e){this.params={operator:"to start with "+d.format(a), | ||
@@ -30,0 +30,0 @@ message:e};this.assert(0===this.obj.indexOf(a))});h.add("endWith",function(a,e){this.params={operator:"to end with "+d.format(a),message:e};this.assert(0<=this.obj.indexOf(a,this.obj.length-a.length))})}},{}],14:[function(h,k,d){var g=h("../util");k.exports=function(d,a){a.add("Number",function(){this.params={operator:"to be a number"};this.assert(g.isNumber(this.obj))},!0);a.add("arguments",function(){this.params={operator:"to be arguments"};this.assert(g.isArguments(this.obj))},!0);a.add("type", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3143
654
267594
5