{ "name": "should", "description": "test framework agnostic BDD-style assertions", "version": "1.2.1", "author": { "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" }, "repository": { "type": "git", "url": "git://github.com/visionmedia/should.js.git" }, "homepage": "https://github.com/visionmedia/should.js", "contributors": [ { "name": "Aseem Kishore", "email": "aseem.kishore@gmail.com" } ], "devDependencies": { "mocha": "*" }, "keywords": [ "test", "bdd", "assert" ], "main": "./lib/should.js", "engines": { "node": ">= 0.2.0" }, "readme": "_should_ is an expressive, readable, test framework agnostic, assertion library for [node](http://nodejs.org).\n\nIt extends the Object prototype with a single non-enumerable getter that allows you to express how that object should behave.\n\n_should_ literally extends node's _assert_ module, in fact, it is node's assert module, for example `should.equal(str, 'foo')` will work, just as `assert.equal(str, 'foo')` would, and `should.AssertionError` **is** `assert.AssertionError`, meaning any test framework supporting this constructor will function properly with _should_.\n\n## Example\n\n var user = {\n name: 'tj'\n , pets: ['tobi', 'loki', 'jane', 'bandit']\n };\n\n user.should.have.property('name', 'tj');\n user.should.have.property('pets').with.lengthOf(4);\n\n someAsyncTask(foo, function(err, result){\n should.not.exist(err);\n should.exist(result);\n result.bar.should.equal(foo);\n });\n\n## Installation\n\n $ npm install should\n\n## assert extras\n\nAs mentioned above, _should_ extends node's _assert_. The returned object from `require('should')` is thus similar to the returned object from `require('assert')`, but it has one extra convenience method:\n\n should.exist('hello')\n should.exist([])\n should.exist(null) // will throw\n\nThis is equivalent to `should.ok`, which is equivalent to `assert.ok`, but reads a bit better. It gets better, though:\n\n should.not.exist(false)\n should.not.exist('')\n should.not.exist({}) // will throw\n\nWe may add more _assert_ extras in the future... ;)\n\n## chaining assertions\n\nSome assertions can be chained, for example if a property is volatile we can first assert property existence:\n\n user.should.have.property('pets').with.lengthOf(4)\n\nwhich is essentially equivalent to below, however the property may not exist:\n\n user.pets.should.have.lengthOf(4)\n\nour dummy getters such as _and_ also help express chaining:\n\n user.should.be.a('object').and.have.property('name', 'tj')\n\n## exist (static)\n\nThe returned object from `require('should')` is the same object as `require('assert')`. So you can use `should` just like `assert`:\n\n should.fail('expected an error!')\n should.strictEqual(foo, bar)\n\nIn general, using the Object prototype's _should_ is nicer than using these `assert` equivalents, because _should_ gives you access to the expressive and readable language described above:\n\n foo.should.equal(bar) // same as should.strictEqual(foo, bar) above\n\nThe only exception, though, is when you can't be sure that a particular object exists. In that case, attempting to access the _should_ property may throw a TypeError:\n\n foo.should.equal(bar) // throws if foo is null or undefined!\n\nFor this case, `require('should')` extends `require('assert')` with an extra convenience method to check whether an object exists:\n\n should.exist({})\n should.exist([])\n should.exist('')\n should.exist(0)\n should.exist(null) // will throw\n should.exist(undefined) // will throw\n\nYou can also check the negation:\n\n should.not.exist(undefined)\n should.not.exist(null)\n should.not.exist('') // will throw\n should.not.exist({}) // will throw\n\nOnce you know an object exists, you can safely use the _should_ property on it.\n\n## ok\n\nAssert truthfulness:\n\n true.should.be.ok\n 'yay'.should.be.ok\n (1).should.be.ok\n\nor negated:\n\n false.should.not.be.ok\n ''.should.not.be.ok\n (0).should.not.be.ok\n\n## true\n\nAssert === true:\n\n true.should.be.true\n '1'.should.not.be.true\n\n## false\n\nAssert === false:\n\n false.should.be.false\n (0).should.not.be.false\n\n## arguments\n\nAssert `Arguments`:\n\n var args = (function(){ return arguments; })(1,2,3);\n args.should.be.arguments;\n [].should.not.be.arguments;\n\n## empty\n\nAsserts that length is 0:\n\n [].should.be.empty\n ''.should.be.empty\n ({ length: 0 }).should.be.empty\n\n## eql\n\nequality:\n\n ({ foo: 'bar' }).should.eql({ foo: 'bar' })\n [1,2,3].should.eql([1,2,3])\n\n## equal\n\nstrict equality:\n\n should.strictEqual(undefined, value)\n should.strictEqual(false, value)\n (4).should.equal(4)\n 'test'.should.equal('test')\n [1,2,3].should.not.equal([1,2,3])\n\n## within\n\nAssert inclusive numeric range:\n\n user.age.should.be.within(5, 50)\n\n## a\n\nAssert __typeof__:\n\n user.should.be.a('object')\n 'test'.should.be.a('string')\n\n## instanceof and instanceOf\n\nAssert __instanceof__ or __instanceOf__:\n\n user.should.be.an.instanceof(User)\n [].should.be.an.instanceOf(Array)\n\n## above\n\nAssert numeric value above the given value:\n\n user.age.should.be.above(5)\n user.age.should.not.be.above(100)\n\n## below\n\nAssert numeric value below the given value:\n\n user.age.should.be.below(100)\n user.age.should.not.be.below(5)\n\n## match\n\nAssert regexp match:\n\n username.should.match(/^\\w+$/)\n\n## length\n\nAssert _length_ property exists and has a value of the given number:\n\n user.pets.should.have.length(5)\n user.pets.should.have.a.lengthOf(5)\n\nAliases: _lengthOf_\n\n## property\n\nAssert property exists and has optional value:\n\n user.should.have.property('name')\n user.should.have.property('age', 15)\n user.should.not.have.property('rawr')\n user.should.not.have.property('age', 0)\n\n## ownProperty\n\nAssert own property (on the immediate object):\n\n ({ foo: 'bar' }).should.have.ownProperty('foo')\n\n## status(code)\n\n Asserts that `.statusCode` is `code`:\n\n res.should.have.status(200);\n\n## header(field[, value])\n\n Asserts that a `.headers` object with `field` and optional `value` are present:\n\n res.should.have.header('content-length');\n res.should.have.header('Content-Length', '123');\n res.should.have.header('content-length', '123');\n\n## json\n\n Assert that Content-Type is \"application/json; charset=utf-8\"\n\n res.should.be.json\n\n## html\n\n Assert that Content-Type is \"text/html; charset=utf-8\"\n\n res.should.be.html\n\n## include(obj)\n\nAssert that the given `obj` is present via `indexOf()`, so this works for strings, arrays, or custom objects implementing indexOf.\n\nAssert array value:\n\n [1,2,3].should.include(3)\n [1,2,3].should.include(2)\n [1,2,3].should.not.include(4)\n\nAssert substring:\n\n 'foo bar baz'.should.include('foo')\n 'foo bar baz'.should.include('bar')\n 'foo bar baz'.should.include('baz')\n 'foo bar baz'.should.not.include('FOO')\n\nAssert object includes another object:\n\n var tobi = { name: 'Tobi', age: 1 };\n var jane = { name: 'Jane', age: 5 };\n var user = { name: 'TJ', pet: tobi };\n\n user.should.include({ pet: tobi });\n user.should.include({ pet: tobi, name: 'TJ' });\n user.should.not.include({ pet: jane });\n user.should.not.include({ name: 'Someone' });\n\n## includeEql(obj)\n\nAssert that an object equal to the given `obj` is present in an Array:\n\n [[1],[2],[3]].should.includeEql([3])\n [[1],[2],[3]].should.includeEql([2])\n [[1],[2],[3]].should.not.includeEql([4])\n\n## throw()\n\nAssert an exception is thrown:\n\n```js\n(function(){\n throw new Error('fail');\n}).should.throw();\n```\n\nAssert an exception is not thrown:\n\n```js\n(function(){\n\n}).should.not.throw();\n```\nAssert exepection message matches string:\n\n```js\n(function(){\n throw new Error('fail');\n}).should.throw('fail');\n```\n\nAssert exepection message matches regexp:\n\n```js\n(function(){\n throw new Error('failed to foo');\n}).should.throw(/^fail/);\n```\n\n## throwError()\n\nAn alias of `throw`, its purpose is to be an option for those who run\n[jshint](https://github.com/jshint/node-jshint/) in strict mode.\n\n```js\n(function(){\n throw new Error('failed to baz');\n}).should.throwError(/^fail.*/);\n```\n\n\n## keys\n\nAssert own object keys, which must match _exactly_,\nand will fail if you omit a key or two:\n\n var obj = { foo: 'bar', baz: 'raz' };\n obj.should.have.keys('foo', 'bar');\n obj.should.have.keys(['foo', 'bar']);\n\n## Optional Error description\n\nAs it can often be difficult to ascertain exactly where failed assertions are coming from in your tests, an optional description parameter can be passed to several should matchers. The description will follow the failed assertion in the error:\n\n (1).should.eql(0, 'some useful description')\n\n AssertionError: expected 1 to equal 0 | some useful description\n at Object.eql (/Users/swift/code/should.js/node_modules/should/lib/should.js:280:10)\n ...\n\nThe methods that support this optional description are: `eql`, `equal`, `within`, `a`, `instanceof`, `above`, `below`, `match`, `length`, `property`, `ownProperty`, `include`, and `includeEql`.\n\n## Express example\n\nFor example you can use should with the [Expresso TDD Framework](http://github.com/visionmedia/expresso) by simply including it:\n\n var lib = require('mylib')\n , should = require('should');\n\n module.exports = {\n 'test .version': function(){\n lib.version.should.match(/^\\d+\\.\\d+\\.\\d+$/);\n }\n };\n\n## Running tests\n\nTo run the tests for _should_ simply update your git submodules and run:\n\n $ make test\n\n## OMG IT EXTENDS OBJECT???!?!@\n\nYes, yes it does, with a single getter _should_, and no it won't break your code, because it does this **properly** with a non-enumerable property.\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2010-2011 TJ Holowaychuk <tj@vision-media.ca>\nCopyright (c) 2011 Aseem Kishore <aseem.kishore@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n", "readmeFilename": "Readme.md", "_id": "should@1.2.1", "_from": "should@*" }