/
package.json
18 lines (18 loc) · 6.52 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"name": "expect.js",
"version": "0.2.0",
"description": "BDD style assertions for node and the browser.",
"main": "./expect",
"devDependencies": {
"mocha": "*",
"serve": "*"
},
"readme": "# Expect\n\nMinimalistic BDD assertion toolkit based on\n[should.js](http://github.com/visionmedia/should.js)\n\n```js\nexpect(window.r).to.be(undefined);\nexpect({ a: 'b' }).to.eql({ a: 'b' })\nexpect(5).to.be.a('number');\nexpect([]).to.be.an('array');\nexpect(window).not.to.be.an(Image);\n```\n\n## Features\n\n- Cross-browser: works on IE6+, Firefox, Safari, Chrome, Opera.\n- Compatible with all test frameworks.\n- Node.JS ready (`require('expect.js')`).\n- Standalone. Single global with no prototype extensions or shims.\n\n## How to use\n\n### Node\n\nInstall it with NPM or add it to your `package.json`:\n\n```\n$ npm install expect.js\n```\n\nThen:\n\n```js\nvar expect = require('expect.js');\n```\n\n### Browser\n\nExpose the `expect.js` found at the top level of this repository.\n\n```html\n<script src=\"expect.js\"></script>\n```\n\n## API\n\n**ok**: asserts that the value is _truthy_ or not\n\n```js\nexpect(1).to.be.ok();\nexpect(true).to.be.ok();\nexpect({}).to.be.ok();\nexpect(0).to.not.be.ok();\n```\n\n**be** / **equal**: asserts `===` equality\n\n```js\nexpect(1).to.be(1)\nexpect(NaN).not.to.equal(NaN);\nexpect(1).not.to.be(true)\nexpect('1').to.not.be(1);\n```\n\n**eql**: asserts loose equality that works with objects\n\n```js\nexpect({ a: 'b' }).to.eql({ a: 'b' });\nexpect(1).to.eql('1');\n```\n\n**a**/**an**: asserts `typeof` with support for `array` type and `instanceof`\n\n```js\n// typeof with optional `array`\nexpect(5).to.be.a('number');\nexpect([]).to.be.an('array'); // works\nexpect([]).to.be.an('object'); // works too, since it uses `typeof`\n\n// constructors\nexpect(5).to.be.a(Number);\nexpect([]).to.be.an(Array);\nexpect(tobi).to.be.a(Ferret);\nexpect(person).to.be.a(Mammal);\n```\n\n**match**: asserts `String` regular expression match\n\n```js\nexpect(program.version).to.match(/[0-9]+\\.[0-9]+\\.[0-9]+/);\n```\n\n**contain**: asserts indexOf for an array or string\n\n```js\nexpect([1, 2]).to.contain(1);\nexpect('hello world').to.contain('world');\n```\n\n**length**: asserts array `.length`\n\n```js\nexpect([]).to.have.length(0);\nexpect([1,2,3]).to.have.length(3);\n```\n\n**empty**: asserts that an array is empty or not\n\n```js\nexpect([]).to.be.empty();\nexpect({}).to.be.empty();\nexpect({ length: 0, duck: 'typing' }).to.be.empty();\nexpect({ my: 'object' }).to.not.be.empty();\nexpect([1,2,3]).to.not.be.empty();\n```\n\n**property**: asserts presence of an own property (and value optionally)\n\n```js\nexpect(window).to.have.property('expect')\nexpect(window).to.have.property('expect', expect)\nexpect({a: 'b'}).to.have.property('a');\n```\n\n**key**/**keys**: asserts the presence of a key. Supports the `only` modifier\n\n```js\nexpect({ a: 'b' }).to.have.key('a');\nexpect({ a: 'b', c: 'd' }).to.only.have.keys('a', 'c');\nexpect({ a: 'b', c: 'd' }).to.only.have.keys(['a', 'c']);\nexpect({ a: 'b', c: 'd' }).to.not.only.have.key('a');\n```\n\n**throwException**/**throwError**: asserts that the `Function` throws or not when called\n\n```js\nexpect(fn).to.throwError(); // synonym of throwException\nexpect(fn).to.throwException(function (e) { // get the exception object\n expect(e).to.be.a(SyntaxError);\n});\nexpect(fn).to.throwException(/matches the exception message/);\nexpect(fn2).to.not.throwException();\n```\n\n**within**: asserts a number within a range\n\n```js\nexpect(1).to.be.within(0, Infinity);\n```\n\n**greaterThan**/**above**: asserts `>`\n\n```js\nexpect(3).to.be.above(0);\nexpect(5).to.be.greaterThan(3);\n```\n\n**lessThan**/**below**: asserts `<`\n\n```js\nexpect(0).to.be.below(3);\nexpect(1).to.be.lessThan(3);\n```\n\n**fail**: explicitly forces failure.\n\n```js\nexpect().fail()\nexpect().fail(\"Custom failure message\")\n```\n\n## Using with a test framework\n\nFor example, if you create a test suite with\n[mocha](http://github.com/visionmedia/mocha).\n\nLet's say we wanted to test the following program:\n\n**math.js**\n\n```js\nfunction add (a, b) { return a + b; };\n```\n\nOur test file would look like this:\n\n```js\ndescribe('test suite', function () {\n it('should expose a function', function () {\n expect(add).to.be.a('function');\n });\n\n it('should do math', function () {\n expect(add(1, 3)).to.equal(4);\n });\n});\n```\n\nIf a certain expectation fails, an exception will be raised which gets captured\nand shown/processed by the test runner.\n\n## Differences with should.js\n\n- No need for static `should` methods like `should.strictEqual`. For example, \n `expect(obj).to.be(undefined)` works well.\n- Some API simplifications / changes.\n- API changes related to browser compatibility.\n\n## Running tests\n\nClone the repository and install the developer dependencies:\n\n```\ngit clone git://github.com/LearnBoost/expect.js.git expect\ncd expect && npm install\n```\n\n### Node\n\n`make test`\n\n### Browser\n\n`make test-browser`\n\nand point your browser(s) to `http://localhost:3000/test/`\n\n## Credits\n\n(The MIT License)\n\nCopyright (c) 2011 Guillermo Rauch <guillermo@learnboost.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\n### 3rd-party\n\nHeavily borrows from [should.js](http://github.com/visionmedia/should.js) by TJ\nHolowaychuck - MIT.\n",
"readmeFilename": "README.md",
"_id": "expect.js@0.2.0",
"dist": {
"shasum": "61891726241ded997d5b0124ed353cae1c07bd69"
},
"_from": "expect.js@~0.2.0",
"_resolved": "https://registry.npmjs.org/expect.js/-/expect.js-0.2.0.tgz"
}