-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.json
95 lines (95 loc) · 13.9 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
"_args": [
[
{
"raw": "chai-as-promised@https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-6.0.0.tgz",
"scope": null,
"escapedName": "chai-as-promised",
"name": "chai-as-promised",
"rawSpec": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-6.0.0.tgz",
"spec": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-6.0.0.tgz",
"type": "remote"
},
"/Users/jennyphan/AngularToolingSamples/Angular4/aboutMe-app/functions/node_modules/firebase-admin"
]
],
"_from": "chai-as-promised@https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-6.0.0.tgz",
"_id": "chai-as-promised@6.0.0",
"_inCache": true,
"_location": "/firebase-admin/chai-as-promised",
"_phantomChildren": {},
"_requested": {
"raw": "chai-as-promised@https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-6.0.0.tgz",
"scope": null,
"escapedName": "chai-as-promised",
"name": "chai-as-promised",
"rawSpec": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-6.0.0.tgz",
"spec": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-6.0.0.tgz",
"type": "remote"
},
"_requiredBy": [],
"_resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-6.0.0.tgz",
"_shasum": "1a02a433a6f24dafac63b9c96fa1684db1aa8da6",
"_shrinkwrap": null,
"_spec": "chai-as-promised@https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-6.0.0.tgz",
"_where": "/Users/jennyphan/AngularToolingSamples/Angular4/aboutMe-app/functions/node_modules/firebase-admin",
"author": {
"name": "Domenic Denicola",
"email": "d@domenic.me",
"url": "https://domenic.me"
},
"bugs": {
"url": "https://github.com/domenic/chai-as-promised/issues"
},
"dependencies": {
"check-error": "^1.0.2"
},
"description": "Extends Chai with assertions about promises.",
"devDependencies": {
"chai": "^3.0.0",
"coffee-script": "1.10.0",
"ecstatic": "^1.3.1",
"glob": "^6.0.1",
"istanbul": "0.4.1",
"jshint": "^2.8.0",
"mocha": "^2.3.4",
"opener": "^1.4.1",
"q": "^1.4.1",
"underscore": "1.8.3"
},
"files": [
"lib"
],
"homepage": "https://github.com/domenic/chai-as-promised#readme",
"keywords": [
"chai",
"chai-plugin",
"browser",
"async",
"testing",
"assertions",
"promises",
"promises-aplus"
],
"license": "WTFPL",
"main": "./lib/chai-as-promised.js",
"name": "chai-as-promised",
"optionalDependencies": {},
"peerDependencies": {
"chai": ">= 2.1.2 < 4"
},
"readme": "<a href=\"http://promisesaplus.com/\">\n <img src=\"https://promises-aplus.github.io/promises-spec/assets/logo-small.png\"\n align=\"right\" valign=\"top\" alt=\"Promises/A+ logo\" />\n</a>\n\n# Chai Assertions for Promises\n\n**Chai as Promised** extends [Chai][chai] with a fluent language for asserting facts about [promises][presentation].\n\nInstead of manually wiring up your expectations to a promise's fulfilled and rejected handlers:\n\n```javascript\ndoSomethingAsync().then(\n function (result) {\n result.should.equal(\"foo\");\n done();\n },\n function (err) {\n done(err);\n }\n);\n```\n\nyou can write code that expresses what you really mean:\n\n```javascript\nreturn doSomethingAsync().should.eventually.equal(\"foo\");\n```\n\nor if you have a case where `return` is not preferable (e.g. style considerations) or not possible (e.g. the testing framework doesn't allow returning promises to signal asynchronous test completion), then you can use the following workaround (where `done()` is supplied by the test framework):\n\n```javascript\ndoSomethingAsync().should.eventually.equal(\"foo\").notify(done);\n```\n\n*Notice*: either `return` or `notify(done)` _must_ be used with promise assertions. This can be a slight departure from the existing format of assertions being used on a project or by a team. Those other assertions are likely synchronous and thus do not require special handling.\n\n## How to Use\n\n### `should`/`expect` Interface\n\nThe most powerful extension provided by Chai as Promised is the `eventually` property. With it, you can transform any existing Chai assertion into one that acts on a promise:\n\n```javascript\n(2 + 2).should.equal(4);\n\n// becomes\nreturn Promise.resolve(2 + 2).should.eventually.equal(4);\n\n\nexpect({ foo: \"bar\" }).to.have.property(\"foo\");\n\n// becomes\nreturn expect(Promise.resolve({ foo: \"bar\" })).to.eventually.have.property(\"foo\");\n```\n\nThere are also a few promise-specific extensions (with the usual `expect` equivalents also available):\n\n```javascript\nreturn promise.should.be.fulfilled;\nreturn promise.should.eventually.deep.equal(\"foo\");\nreturn promise.should.become(\"foo\"); // same as `.eventually.deep.equal`\nreturn promise.should.be.rejected;\nreturn promise.should.be.rejectedWith(Error); // other variants of Chai's `throw` assertion work too.\n```\n\n### `assert` Interface\n\nAs with the `should`/`expect` interface, Chai as Promised provides an `eventually` extender to `chai.assert`, allowing any existing Chai assertion to be used on a promise:\n\n```javascript\nassert.equal(2 + 2, 4, \"This had better be true\");\n\n// becomes\nreturn assert.eventually.equal(Promise.resolve(2 + 2), 4, \"This had better be true, eventually\");\n```\n\nAnd there are, of course, promise-specific extensions:\n\n```javascript\nreturn assert.isFulfilled(promise, \"optional message\");\n\nreturn assert.becomes(promise, \"foo\", \"optional message\");\nreturn assert.doesNotBecome(promise, \"foo\", \"optional message\");\n\nreturn assert.isRejected(promise, \"optional message\");\nreturn assert.isRejected(promise, Error, \"optional message\");\nreturn assert.isRejected(promise, /error message matcher/, \"optional message\");\n```\n\n### Progress Callbacks\n\nChai as Promised does not have any intrinsic support for testing promise progress callbacks. The properties you would want to test are probably much better suited to a library like [Sinon.JS][sinon], perhaps in conjunction with [Sinon–Chai][sinon-chai]:\n\n```javascript\nvar progressSpy = sinon.spy();\n\nreturn promise.then(null, null, progressSpy).then(function () {\n progressSpy.should.have.been.calledWith(\"33%\");\n progressSpy.should.have.been.calledWith(\"67%\");\n progressSpy.should.have.been.calledThrice;\n});\n```\n\n### Customizing Output Promises\n\nBy default, the promises returned by Chai as Promised's assertions are regular Chai assertion objects, extended with a single `then` method derived from the input promise. To change this behavior, for instance to output a promise with more useful sugar methods such as are found in most promise libraries, you can override `chaiAsPromised.transferPromiseness`. Here's an example that transfer's Q's `finally` and `done` methods:\n\n```js\nchaiAsPromised.transferPromiseness = function (assertion, promise) {\n assertion.then = promise.then.bind(promise); // this is all you get by default\n assertion.finally = promise.finally.bind(promise);\n assertion.done = promise.done.bind(promise);\n};\n```\n\n### Transforming Arguments to the Asserters\n\nAnother advanced customization hook Chai as Promised allows is if you want to transform the arguments to the asserters, possibly asynchronously. Here is a toy example:\n\n```js\nchaiAsPromised.transformAsserterArgs = function (args) {\n return args.map(function (x) { return x + 1; });\n}\n\nPromise.resolve(2).should.eventually.equal(2); // will now fail!\nPromise.resolve(3).should.eventually.equal(2); // will now pass!\n```\n\nThe transform can even be asynchronous, returning a promise for an array instead of an array directly. An example of that might be using `Promise.all` so that an array of promises becomes a promise for an array. If you do that, then you can compare promises against other promises using the asserters:\n\n```js\n// This will normally fail, since within() only works on numbers.\nPromise.resolve(2).should.eventually.be.within(Promise.resolve(1), Promise.resolve(6));\n\nchaiAsPromised.transformAsserterArgs = function (args) {\n return Promise.all(args);\n};\n\n// But now it will pass, since we transformed the array of promises for numbers into\n// (a promise for) an array of numbers\nPromise.resolve(2).should.eventually.be.within(Promise.resolve(1), Promise.resolve(6));\n```\n\n### Compatibility\n\nChai as Promised is compatible with all promises following the [Promises/A+ specification][spec].\n\nNotably, jQuery's promises were not up to spec before jQuery 3.0, and Chai as Promised will not work with them. In particular, Chai as Promised makes extensive use of the standard [transformation behavior][] of `then`, which jQuery<3.0 does not support.\n\nAngular promises have a special digest cycle for their processing, and [need extra setup code to work with Chai as Promised](http://stackoverflow.com/a/37374041/3191).\n\n### Working with Non-Promise–Friendly Test Runners\n\nSome test runners (e.g. Jasmine, QUnit, or tap/tape) do not have the ability to use the returned promise to signal asynchronous test completion. If possible, I'd recommend switching to ones that do, such as [Mocha][mocha-promises], [Buster][buster-promises], or [blue-tape][]. But if that's not an option, Chai as Promised still has you covered. As long as your test framework takes a callback indicating when the asynchronous test run is over, Chai as Promised can adapt to that situation with its `notify` method, like so:\n\n```javascript\nit(\"should be fulfilled\", function (done) {\n promise.should.be.fulfilled.and.notify(done);\n});\n\nit(\"should be rejected\", function (done) {\n otherPromise.should.be.rejected.and.notify(done);\n});\n```\n\nIn these examples, if the conditions are not met, the test runner will receive an error of the form `\"expected promise to be fulfilled but it was rejected with [Error: error message]\"`, or `\"expected promise to be rejected but it was fulfilled.\"`\n\nThere's another form of `notify` which is useful in certain situations, like doing assertions after a promise is complete. For example:\n\n```javascript\nit(\"should change the state\", function (done) {\n otherState.should.equal(\"before\");\n promise.should.be.fulfilled.then(function () {\n otherState.should.equal(\"after\");\n }).should.notify(done);\n});\n```\n\nNotice how `.notify(done)` is hanging directly off of `.should`, instead of appearing after a promise assertion. This indicates to Chai as Promised that it should pass fulfillment or rejection directly through to the testing framework. Thus, the above code will fail with a Chai as Promised error (`\"expected promise to be fulfilled…\"`) if `promise` is rejected, but will fail with a simple Chai error (`expected \"before\" to equal \"after\"`) if `otherState` does not change.\n\n### Multiple Promise Assertions\n\nTo perform assertions on multiple promises, use `Promise.all` to combine multiple Chai as Promised assertions:\n\n```javascript\nit(\"should all be well\", function () {\n return Promise.all([\n promiseA.should.become(\"happy\"),\n promiseB.should.eventually.have.property(\"fun times\"),\n promiseC.should.be.rejectedWith(TypeError, \"only joyful types are allowed\")\n ]);\n});\n```\n\nThis will pass any failures of the individual promise assertions up to the test framework, instead of wrapping them in an `\"expected promise to be fulfilled…\"` message as would happen if you did `return Promise.all([…]).should.be.fulfilled`. If you can't use `return`, then use `.should.notify(done)`, similar to the previous examples.\n\n## Installation and Setup\n\n### Node\n\nDo an `npm install chai-as-promised` to get up and running. Then:\n\n```javascript\nvar chai = require(\"chai\");\nvar chaiAsPromised = require(\"chai-as-promised\");\n\nchai.use(chaiAsPromised);\n\n// Then either:\nvar expect = chai.expect;\n// or:\nvar assert = chai.assert;\n// or:\nchai.should();\n// according to your preference of assertion style\n```\n\nYou can of course put this code in a common test fixture file; for an example using [Mocha][], see [the Chai as Promised tests themselves][fixturedemo].\n\n### In the Browser\n\nTo use Chai as Promised in environments that don't support Node.js-like CommonJS modules, you'll need to use a bundling tool like [browserify][].\n\n### Karma\n\nIf you're using [Karma][], check out the accompanying [karma-chai-as-promised][] plugin.\n\n### Browser Compatibility\n\nChai as Promised is only compatible with modern browsers (IE ≥9, Safari ≥6, no PhantomJS).\n\n[presentation]: http://www.slideshare.net/domenicdenicola/callbacks-promises-and-coroutines-oh-my-the-evolution-of-asynchronicity-in-javascript\n[chai]: http://chaijs.com/\n[Mocha-promises]: http://mochajs.org/#asynchronous-code\n[Buster-promises]: http://docs.busterjs.org/en/latest/modules/buster-test/spec/#returning-a-promise\n[blue-tape]: https://github.com/spion/blue-tape\n[spec]: http://promisesaplus.com/\n[transformation behavior]: http://domenic.me/2012/10/14/youre-missing-the-point-of-promises/#toc_2\n[Mocha]: http://mochajs.org\n[fixturedemo]: https://github.com/domenic/chai-as-promised/tree/master/test/\n[amd]: https://github.com/amdjs/amdjs-api/wiki/AMD\n[sinon]: http://sinonjs.org/\n[sinon-chai]: https://github.com/domenic/sinon-chai\n[Karma]: https://karma-runner.github.io/\n[karma-chai-as-promised]: https://github.com/vlkosinov/karma-chai-as-promised\n[browserify]: http://browserify.org/\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/domenic/chai-as-promised.git"
},
"scripts": {
"cover": "istanbul cover node_modules/mocha/bin/_mocha && opener ./coverage/lcov-report/lib/chai-as-promised.js.html",
"lint": "jshint ./lib",
"test": "npm run test-plugin && npm run test-intercompatibility",
"test-intercompatibility": "mocha test-intercompatibility --opts test-intercompatibility/mocha.opts",
"test-plugin": "mocha"
},
"version": "6.0.0"
}