{"_id":"o-testing-toolbox","_rev":"4-0bb46489d8708628db361d1b0edda6d8","name":"o-testing-toolbox","dist-tags":{"latest":"2.0.1"},"versions":{"1.0.0":{"name":"o-testing-toolbox","version":"1.0.0","description":"Additional expectations for `chai` package and other utilities","main":"index.js","scripts":{"test":"npx mocha --config ./utilities-config/.mocharc.json"},"keywords":["mocha","chai","expectations","testing"],"author":{"name":"Martin Rubi"},"license":"ISC","devDependencies":{"chai":"^4.2.0","eslint":"^7.0.0","eslint-config-standard":"^14.1.1","eslint-plugin-import":"^2.20.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","express":"^4.17.1","mocha":"^7.1.0","nyc":"^15.0.0","supertest":"^4.0.2"},"dependencies":{"o-method-proxy":"^1.0"},"gitHead":"22891b2a287a01780e48ba132321b44e0782a3b0","_id":"o-testing-toolbox@1.0.0","_nodeVersion":"12.16.2","_npmVersion":"6.14.4","dist":{"integrity":"sha512-zmxFNzYaHIwmtTAmA2BI0vnjgoQ+jN/fgQajLjg7w/HhpUD4NKYUmxQu/2E3GZ2o+/riTP7xjSnncA5pTDz04A==","shasum":"194a749253e5d1bdcca9bd864a38bc9e063a1250","tarball":"https://registry.npmjs.org/o-testing-toolbox/-/o-testing-toolbox-1.0.0.tgz","fileCount":38,"unpackedSize":71207,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe25QZCRA9TVsSAnZWagAAivEP/iao6yR1W5EQz3+7CUQi\n8Ir3/Vo1EnEKuIYT/sh/+cJIQ/nbWzh6c4rYhE3LrkEuGfEvxvuo+/6iujeR\ngae/08GAG06X+fsyib+U3wUm5u7GEmseqTI5HoEXjo35lKLz7ga+FEEl/5yH\ndREfNIaqo5cO6KYHtDrUhgTZG59qkAQoB9AuALVlc91VC5wP4D7bKuNdPK/x\nhl2W0LyG04baTPBC8kFJhnw3SCCMoLc9q6MhSIJ6a28Afsx/AkhInFR4P4ql\n1Q5jLOdUC76xjP4O+oYHcQJa5e2eq+LTotag/iP4D65P9PvlxTChExot2ZUq\njXJpmx31M3fKkDke8GVJupABsMffo45L3C1hQ3lGEygzLreDVY/WMtP7c8du\n2XRSOcyX01jj/gJ6qUd1CpI5EfiwZeNKTLq1UNgbj0JaF6T32oc6O5cyt4Mn\nKndj2Npu2OwbTDMmgi/vW9BOeKIRlxlCO0ImU89LtXHdmuYrXkiuShbIepvK\nd0Dj6SIZO+/SmbfwX9Ab0HG9cRKQnj7mJSJ30zGiiRvlp8hdSYySSyVM4fXe\nL7Uhez5Jh/hgGBtUUlyKkyRIrQQq/bdAI6BDevuV2iOOU/Ij9CLmipj5dMzB\nX8luIAew28FcEKb+Mz9xZiWuaYPf4T/swT9AYRgPWLOTwo4j6X1tXYVblaha\nCjdT\r\n=yPse\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCd5T0sNJZ5cQ1wLyepP98yWE/hBcLswLgtyHEUHRACwgIgDQiNX91pIlBB8sjcfRa80uYF8vS92Pm4awAafVV7ol0="}]},"maintainers":[{"name":"haijindev","email":"haijin.development@gmail.com"}],"_npmUser":{"name":"haijindev","email":"haijin.development@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/o-testing-toolbox_1.0.0_1591448600674_0.603414216093108"},"_hasShrinkwrap":false},"1.0.1":{"name":"o-testing-toolbox","version":"1.0.1","description":"Additional expectations for `chai` package and other utilities","main":"index.js","scripts":{"test":"npx mocha --config ./utilities-config/.mocharc.json"},"keywords":["mocha","chai","expectations","testing"],"author":{"name":"Martin Rubi"},"license":"ISC","devDependencies":{"chai":"^4.2.0","eslint":"^7.0.0","eslint-config-standard":"^14.1.1","eslint-plugin-import":"^2.20.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","express":"^4.17.1","mocha":"^7.2.0","nyc":"^15.0.0","supertest":"^4.0.2"},"dependencies":{"o-method-proxy":"^1.0"},"gitHead":"1c0e16a42280efcedecb40142e727286ac52b6f4","_id":"o-testing-toolbox@1.0.1","_nodeVersion":"12.16.2","_npmVersion":"6.14.4","dist":{"integrity":"sha512-gNw90t5lPqfG2RD+oW2V9ucJLCRMPUt8+ZgQlemUzQBEvMwKgJmhJNrHVEtYhmMxxU34WvAscT1pjQFIhE3+vg==","shasum":"fabdff0e86bce5dae6eb74abfe17ede526dce085","tarball":"https://registry.npmjs.org/o-testing-toolbox/-/o-testing-toolbox-1.0.1.tgz","fileCount":38,"unpackedSize":71316,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe5LQ9CRA9TVsSAnZWagAA3joP/2Hg2GCDcN/wCdL+Ginv\ngk5+78hpreU3rCKko4Pzi6TiCHgGXv7uimIhgqNgCIeaVJ2V8H2KRSTi9RyZ\n8R6R3f36Dje5tAzI+GTYHdAaOFUmp5c3ry4+MXxT7SipvsQwOhmominaSIC+\n3XFLGS9X/cYKGMMgR+IN0eM5foobu5H8nr1OxYHBZlwzlNF7pXoTC5iqwl4Y\nT3touR95M4sDNExPQRCmaRY71DIltwN0LLyIK4i10q9Z/vSGVboVhK18kyF8\noSn+77fPbIj/P1gwyETESn4SdqcE54SWnCSEJ2z23dm1f2w1+oiCuhNfqfQd\n39spsATHEtr8eaq1M/IquwFab/0NjnZKwpm//42Kll47zeKsI+watvxnaO17\nkx7TCG54+7eeFhb7yWmapaJj3wXOULXHt8iCDYZCOxLc627GBmJiPIU97rOv\nX8kdolJLnMmk8htl6LACIIMZAu9BwVQ/k42iwy82UG2WFQqRk6YGhS+2E7Nk\n51pCYowGgsJ+mcq4QLQNQpTTLSfAQlvguu5CpzU2OfzlR60xYP7GBo8zDmml\n84Zl5hzNEvPCTIKoFxiZXHJJ4P/19vic9ltXNjFKFFidpbGKLdgJxqueR74b\nJc23QT9ol3txS8Je8qUkHL2EYMcitQxMSsM70hNmQk8PKibCq+4yFM8VESxG\np7V4\r\n=/uAx\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFjtYMMknasnLQtPjlSXdOYuoEZcw4+xMmpi/2szjjGtAiEAzl8NRB/kUxkGhUcfKXSwROk0OOHLyxCx9uglZATN5pI="}]},"maintainers":[{"name":"haijindev","email":"haijin.development@gmail.com"}],"_npmUser":{"name":"haijindev","email":"haijin.development@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/o-testing-toolbox_1.0.1_1592046652482_0.5687818120514718"},"_hasShrinkwrap":false},"2.0.0":{"name":"o-testing-toolbox","version":"2.0.0","description":"Additional expectations for `chai` package and other testing utilities","main":"index.js","scripts":{"test":"npx mocha --config ./utilities-config/.mocharc.json"},"keywords":["mocha","chai","expectations","testing"],"author":{"name":"Martin Rubi"},"license":"ISC","homepage":"https://bitbucket.org/haijin-development/testing-toolbox","devDependencies":{"chai":"^4.2.0","eslint":"^7.0.0","eslint-config-standard":"^14.1.1","eslint-plugin-import":"^2.20.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","express":"^4.17.1","mocha":"^7.2.0","nyc":"^15.0.0"},"dependencies":{"o-method-proxy":"^1.0"},"gitHead":"41afea40f0711ee5580323f61ce2b3c6c3a90913","_id":"o-testing-toolbox@2.0.0","_nodeVersion":"12.16.2","_npmVersion":"6.14.4","dist":{"integrity":"sha512-ypMY9e+5XwlpafzXYfW+mYKI8+DXghU3yY/FrrPa2HQY7Ys665DarRZAdmAXk7nJSsJBT8MFpCcVMxvoNc7Kqg==","shasum":"645dc33a3342802bad22b7abea7394bcbc5d0885","tarball":"https://registry.npmjs.org/o-testing-toolbox/-/o-testing-toolbox-2.0.0.tgz","fileCount":35,"unpackedSize":68349,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfeMZvCRA9TVsSAnZWagAAGhQP/12df8n2DBD8NLxvnx3k\ngSx5Te+7lYF4W4BsftweYTbOIeyjMLpnfuWmsOnWQMEqHlX5J0uBM5klsgnq\nt5xk82NOZr/D4yD3md7TUlUrGIjM7ka2HDo2P4CICJm99LAqSrIX6b8AUoiF\n6bHvXESD4soODkICWl7OgrK5pUID85LVs0mXE6iAH077tdRHnUg9yyIRc+yP\n9Hen4MKRtfC71YOqVTNh0zD+uc53K2HL2beFWAQQOvR3BIb+ydM3Idh/Fw9J\n5/9N3lKxLwOt5b4/ilgMJ98mEQNbyAh7dcK85ELvLKVMlNdLsd9alNDNLSb9\nDYONm/l83WzZLO9QSZx5mOgpMTdW687uAWhAHgbhbR/OgBcL4z9p8/lg3aXl\n+C2LmEHsG/SNVM5jfQhjwBlyL0+OoMweA9xnaJphnnPqFZX55h6Q24R7Lvte\ngIcDv6TLdANNdK44aaX872gv5MRJSby9g/c3WYTE1Yl4+TUfD0qVcM3jrZ2c\nbJ2FuqHyhZ0GZ+3gq0NSI7bA69dWPLGYNHO2B9P4K4R7kzvL6VVYWe8ZiDrA\naxBFc6kizzKbh38XP9FxOXpGk0VJKPYhcfi2R7VcPXPXj/iA2jSzFJV/iT3a\nRzCE4XgDOux1OViiTE2xwDy74x9N/wsicVCOt2oAcplWtBEjFIlGSCSAL8qM\nGq69\r\n=cntI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDHKbOxOJGvQV2nE1xXxycvoCqY5nPbr1jKUwtrMM6S4gIhALJWxCYztP65E8/zM0UcBWYWwNC8M3zBda+oNjkwv6WZ"}]},"maintainers":[{"name":"haijindev","email":"haijin.development@gmail.com"}],"_npmUser":{"name":"haijindev","email":"haijin.development@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/o-testing-toolbox_2.0.0_1601750639211_0.6803320184439761"},"_hasShrinkwrap":false},"2.0.1":{"name":"o-testing-toolbox","version":"2.0.1","description":"Additional expectations for `chai` package and other testing utilities","main":"index.js","scripts":{"test":"npx mocha --config ./utilities-config/.mocharc.json"},"keywords":["mocha","chai","expectations","testing"],"author":{"name":"Martin Rubi"},"license":"ISC","homepage":"https://bitbucket.org/haijin-development/testing-toolbox","devDependencies":{"chai":"^4.2.0","eslint":"^7.13.0","eslint-config-standard":"^16.0.1","eslint-plugin-import":"^2.22.1","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.1.0","express":"^4.17.1","mocha":"^7.2.0","nyc":"^15.1.0"},"dependencies":{"o-method-proxy":"^1.0.0"},"gitHead":"e3b2eabfb4c1c5f7e4cae7604b19111501cc1660","_id":"o-testing-toolbox@2.0.1","_nodeVersion":"14.12.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-Dq+NF1Y2vOGRhCTbUJItFQ86Vvt6arOFvRHeXSB2zYbQ02fVCQgZnuIQZDXhxlGEtkty5mm3tI9EY/uh5kbufg==","shasum":"61d653e50ac1ae3af476e24c97b6ccb78fea3a69","tarball":"https://registry.npmjs.org/o-testing-toolbox/-/o-testing-toolbox-2.0.1.tgz","fileCount":35,"unpackedSize":68360,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfr/i1CRA9TVsSAnZWagAA0xMQAJDVDbSMKTib51jlF5Qc\nX20pa1S+dkRCsf4jz7hFRBNgrIQJt8vApQihsnvEmL16evaVXBqHF6KiWiTD\nlPMt84QhyRgUl3rGJCCPCvsIR6WEmKedYywclXd5up8M44hAbUut2IRGqUyn\nz8mjx423BMRJ6RuAympxrzQmYh1EitNiQ1+0CargbYkoHHGVMuFpdYetCmEB\nJfWtCo/NcUgV/gEy7poUuFu2rMKp0wAt/YPXO9/dJ90liSg50n0KtpCyDnMg\niqKLsCH1HKJ7X5qCwkchQWPDWd3p5v9FFjM1jRiJvMOngUi6oprx/NXf4xln\nW77szf1ovMo5SEXP8aMg9jRXjPOG0vr907UIBIYxaZsipMjrA3qIyzO05RRM\n7Aa+cu7+RwAkPdn4DDxFs3zKz7ePRrsyTTF0JQWRTdu4evSSftka5GbghBq9\n3mff+kLOJ+BBzjpIv4c8KNqX59dBCb//xugPLUOzCJXFxCM4qmzn0nrcVsIK\nQdcwUQcVuzUPOHSW/+OBWEGo1wDXLGeb+A0DrV5SX7mS9laFXfrYw2e2wgvz\nYum9Xlhs+CDYrMnn9uZb/zisDLYb8UawbKm0lYV08gaSiqe5GjZIpX+zzP4J\noNfg9i5u03tW5hKoEPSkGL+B8BBeL8kOc/l21MKEbJQh8kuSIF6Sna60OTVz\nwVxn\r\n=xTjc\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDWhNlTM0Qy6AUJfllYts+5Wwbojw9d4fQmBu3QY6pg7gIhAOfM/Q4IOSYhWHjTZDR8wR1L/yr6Nb0t7iLd+4XlECuo"}]},"_npmUser":{"name":"haijindev","email":"haijin.development@gmail.com"},"directories":{},"maintainers":[{"name":"haijindev","email":"haijin.development@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/o-testing-toolbox_2.0.1_1605367988404_0.7609178483059342"},"_hasShrinkwrap":false}},"time":{"created":"2020-06-06T13:03:20.673Z","1.0.0":"2020-06-06T13:03:20.835Z","modified":"2022-05-12T00:03:40.650Z","1.0.1":"2020-06-13T11:10:52.642Z","2.0.0":"2020-10-03T18:43:59.353Z","2.0.1":"2020-11-14T15:33:08.610Z"},"maintainers":[{"name":"haijindev","email":"haijin.development@gmail.com"}],"description":"Additional expectations for `chai` package and other testing utilities","keywords":["mocha","chai","expectations","testing"],"author":{"name":"Martin Rubi"},"license":"ISC","readme":"# testing-toolbox\n\nAdditional expectations for `chai` package and other utilities\n\n- [Installation](#installation)\n- [Usage](#usage)\n    - [Defining variables with letBe statements](#letBe)\n    - [Defining helper methods with letBeMethod statements](#letBeMethod)\n    - [Async expectation](#async-expectations-tests)\n    - [Collection expectations](#collection-expectations)\n    - [chain expectations](#chain-expectations)\n    - [Json expectations](#json-expectations)\n    - [File expectations](#file-expectations)\n    - [Skipping slow tests](#skipping-slow-tests)\n    - [Expected code styles](#expected-code-styles)\n    - [Expected code coverage](#expected-code-coverages)\n\n<a name=\"installation\"></a>\n## Installation\n\nInstall the package with\n\n```\nnpm install --save-dev o-testing-toolbox\n```\n<a name=\"usage\"></a>\n## Usage\n\n<a name=\"letBe\"></a>\n### Defining variables with letBe statements\n\nFor this extension to work first you need to install the following packages:\n\n```\nnpm install --save-dev mocha\nnpm install --save-dev chai\n```\n\nFirst include the `LetBeExtesion` plugin for `chai` in your test file\n\n```javascript\nconst chai = require('chai')\nconst {expect} = require('chai')\nconst {LetBeExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\n```\n\nThen define a variable with\n\n```javascript\nletBe.loginUrl = () => '/login'\n```\n\n(read it `let loginUrl be '/login'` like in math: `let O be a not empty set`)\n\nIf the value is a literal it is possible to use the shortcut\n\n```javascript\nletBe.loginUrl = '/login'\n```\n\nNote that using the shortcut does not assign the value. It wraps it with an initializer. It also freezes\nthe constant to avoid errors caused by secondary effects on the variable object. As a rule of thumb always use the first form.\n\nletBe definitions can be anywhere in the test:\n\n- in the outer scope\n\n```javascript\nbeforeEach( () => {\n  letBe.loginUrl = () => '/login'\n})\n\ndescribe('The login endpoint', () => {\n  ...\n})\n```\n\n- in the inner scope\n\n```javascript\ndescribe('The login endpoint', () => {\n  beforeEach( () => {\n    letBe.loginUrl = () => '/login'\n  })\n\n  ...\n})\n```\n\n- in the inner nested scope\n\n```javascript\ndescribe('The login endpoint', () => {\n  describe('returns 200', () => {\n    beforeEach( () => {\n      letBe.loginUrl = () => '/login'\n    })\n  })\n\n  ...\n})\n```\n\n- in the test scope\n\n```javascript\ndescribe('The login endpoint', () => {\n  it('returns 200', () => {\n    letBe.loginUrl = () => '/login'\n  })\n\n  ...\n})\n```\n\nAvoid defining letBe statements out of a `beforeEach` or `before` block\n\n\n```javascript\n// Not good. This assignment is global and it's executed only once when the file is required\nletBe.loginUrl = () => '/login'\n\ndescribe('The login endpoint', () => {\n  it('returns 200', () => {\n  })\n\n  ...\n})\n```\n\n```javascript\n// Good. This assigment is loaded once when the file is required but it's evaluated before each test\nbeforeEach( () => {\n  letBe.loginUrl = () => '/login'\n})\n\ndescribe('The login endpoint', () => {\n  it('returns 200', () => {\n  })\n\n  ...\n})\n```\n\nTo use a variable defined with letBe reference it like any other variable\n\n```javascript\nbefore( () => {\n  letBe.loginUrl = () => '/login'\n})\n\ndescribe('The login endpoint', () => {\n  it('returns 200', () => {\n    const response = httpClient.get(loginUrl)\n\n    expect(response.statusCode).to.eql(200)\n  })\n})\n```\n\nIt is possible to override letBe variables at any scope and still reference them from outer scopes\n\n```javascript\nbefore( () => {\n  letBe.httpClient = () => new HttpClient()\n  letBe.userUrl = () => `/users/${userId}`\n  letBe.httpResponse = () => httpClient.get(userUrl)\n  letBe.responseStatusCode = () => httpResponse.statusCode\n})\n\ndescribe('The users endpoint', () => {\n  describe('for an existent user', () => {\n    beforeEach( () => {\n      letBe.userId = () => 1\n    })\n\n    it('returns 200', () => {\n      expect(responseStatusCode).to.eql(200)\n    })\n  })\n\n  describe('for an inexistent user', () => {\n    beforeEach( () => {\n      letBe.userId = () => 2\n    })\n\n    it('returns 404', () => {\n      expect(responseStatusCode).to.eql(404)\n    })\n  })\n})\n```\n\n\nThe differences between using a regular variable assigment\n\n```javascript\nconst loginUrl = '/login'\n\ndescribe('The login endpoint', () => {\n  ...\n})\n```\n\nand a letBe definition are\n\n- a letBe variable is lazily initialized on its first use, not on its definition\n- (that means that) a letBe definition can reference other letBe definitions without caring about the order of declarations. That may or may not improve the understanding of the test but can be used to override letBe variables within inner scopes. See the previous example\n- also, it means that if a letBe variable is not used in a test it won't be initialized in that tests. Keep it in mind if your variable has expected side effects like creating items in a database\n- letBe variables can not be assigned with a value after its initialization. They behave like `const` variables\n- all letBe variables are always unset before and after each test run. That makes each test to start fresh and avoids side effects from previous tests\n\n<a name=\"letBeMethod\"></a>\n### Defining helper methods with letBeMethod statements\n\nIf there is common or complex code in the tests is can be extracted to a method with the statement\n\n```javascript\nletBeMethod.sum = function(a, b) { return a + b }\n```\n\n`letBeMethod` statements behave exactly like `letBe` variables.\n\n\n<a name=\"async-expectations-tests\"></a>\n### Async expectation\n\nExpress expectations on Promises with\n\n```javascript\nconst chai = require('chai')\nconst {expect} = require('chai')\nconst {LetBeExtension, AsyncExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(AsyncExtension)\n\n\ndescribe('A test expecting a promised value', () => {\n  before(() => {\n    letBe.promisedValue = () => Promise.resolve(1)\n  })\n\n  it('validates the promise resolution', (done) => {\n    expect(promisedValue).to.eventually.be.above(0)\n      .endWith(done)\n  })\n})\n```\n\nThe expectation must end with `.endWith(done)`\n\n<a name=\"collection-expectations\"></a>\n### Collection expectations\n\nThese assertions are available in the `CollectionExtension`\n\n```javascript\nconst chai = require('chai')\nconst {expect} = require('chai')\nconst {LetBeExtension, CollectionExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(CollectionExtension)\n\ndescribe('A test', () => {\n  it('expects a single item', () => {\n    expect(aCollection).onlyItem.to.be ...\n  })\n  it('expects at least 1 item', () => {\n    expect(aCollection).firstItem.to.be ...\n  })\n  it('expects at least a second item', () => {\n    expect(aCollection).secondItem.to.be ...\n  })\n  it('expects at least a third item', () => {\n    expect(aCollection).thirdItem.to.be ...\n  })\n  it('expects at least a n items', () => {\n    expect(aCollection).atIndex(n).to.be ...\n  })\n  it('expects at least 1 last item', () => {\n    expect(aCollection).lastItem.to.be ...\n  })\n})\n```\n\nThese expectations usually get along well with `.satisfy`, `.suchThat` and `.expecting`\n\n```javascript\nit('expects a collection with exactly one item', () => {\n  expect(users).onlyItem.to.be.suchThat((user) => {\n    expect(user.name).to.equal('John')\n    expect(user.lastName).to.equal('Doe')\n  })\n})\n```\n\nand `.samePropertiesThan`\n\n```javascript\nit('expects a collection with exactly one item', () => {\n  expect(users).onlyItem.to.have.samePropertiesThan({\n    name: 'John',\n    lastName: 'Doe'\n  })\n})\n```\n\n<a name=\"chain-expectations\"></a>\n### chain expectations\n\nThese assertions are available in the `ChainExtension`\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, ChainExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(ChainExtension)\n```\n\n### suchThat expectation\n\nTo express custom expectations on a nested attribute do\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, ChainExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(ChainExtension)\n\nit('expects a collection with exactly one item with a given name', () => {\n  expect(users).onlyItem.suchThat((user) => {\n    expect(user.name).to.equal('John')\n  })\n})\n```\n\n### make expectation\n\nTo assert that an action has some side effect on other objects do\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, ChainExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(ChainExtension)\n\nit('expects a block to have an effect', () => {\n  let value = 0\n  expect(()=>{\n    value += 1\n  }).to.make(()=> value).to.equal(1)\n})\n```\n\nNote that `make` always takes a block as its parameter and not a value.\nThe reason is that a parameter would be evaluated before calling the `.make` assertion\nand therefore before the evaluation of the `expect` block.\n\nThis expectation can be used to test state after some event like a click or receiving a request occurs.\n\n### after expectation\n\nChanges the subject of the assertion chain setting it to the result of the evaluation of the given block\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, ChainExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(ChainExtension)\n\nit('expects a block to have an effect', () => {\n  expect(1).after((n)=>n*10).to.equal(10)\n})\n```\n\n\nThis expectation can be combined with `.make` to express assertions like\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, ChainExtension} = require('o-testing-toolbox')\n\nit('expects a button to invoke its onClicked handler', () => {\n  const user = new UserEmulator()\n  let clickedValue = false\n  const button = new Button({ onClicked: ()=>{clickedValue = true} })\n\n  expect(button)\n    .after((btn)=> user.click(btn))\n    .to.make(()=>clickedValue).to.be.true\n  })\n})\n```\n\nas a simple alternative to the use of mock assertions.\n\n\n### expecting expectation\n\nTakes a block with the subject as its parameter to allow multiple assertions on the subject.\n\nFor example\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, ChainExtension} = require('o-testing-toolbox')\n\nit('expects a list to have two items', () => {\n  expect(list).expecting((list) => {\n    list.to.have.firstItem.equalTo(10)\n    list.to.have.secondItem.equalTo(11)\n  })\n})\n```\n\nWith a regular assertions chain it would not be possible to make further assertions on the `list` object after the `.firstItem` assertion since it would have change the assertion subject.\n\nAfter the evaluation of the block it is possible to continue with assertions on the original subject.\n\nFor example\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, ChainExtension} = require('o-testing-toolbox')\n\nit('expects a list to have two items', () => {\n  expect(list).expecting((list) => {\n    list.to.have.firstItem.equalTo(10)\n    list.to.have.secondItem.equalTo(11)\n  }).to.have.length(2)\n})\n```\n\n### equalTo, eqlTo and matching expectations\n\n`equalTo`, `eqlTo` and `matching` expectations are synonyms of `equal`, `eql` and `match`.\n\nThey are meant to be used when they might make an assertion more readable, for example\n\n```\nexpect(component).to.have.div.with.text.equalTo('A text')\n```\n\n<a name=\"json-expectations\"></a>\n### Json expectations\n\nAssert expectations on nested structures with\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, JsonExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(JsonExtension)\n\ndescribe('A test', () => {\n  beforeEach(() => {\n    letBe.expectedObject = {\n      order: {\n        id: 1,\n        products: [\n          oranges: 1\n        ]\n      }\n    }\n  })\n\n  it('expects all the nested properties to match exactly', () => {\n    expect(response.body).to.have.samePropertiesThan(expectedObject)\n  })\n})\n```\n\nIf you need only a partial match do\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, JsonExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(JsonExtension)\n\ndescribe('A test', () => {\n  beforeEach(() => {\n    letBe.expectedObject = {\n      order: {\n        products: [\n          oranges: 1\n        ]\n      }\n    }\n  })\n\n  it('expects the actual object to have the expectedProperties but it is ok if it has others', () => {\n    expect(response.body).to.have.allPropertiesIn(expectedProperties)\n  })\n})\n```\n\nIf you need to assert that the actual object does not have other properties than the expected ones do\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, JsonExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(JsonExtension)\n\ndescribe('A test', () => {\n  beforeEach(() => {\n    letBe.expectedObject = {\n      order: {\n        products: [\n          oranges: 1\n        ]\n      }\n    }\n  })\n\n  it('expects the actual object not to have other properties that the ones in expectedProperties', () => {\n    expect(response.body).to.have.noOtherPropertiesThan(expectedProperties)\n  })\n})\n```\n\nIf you need to assert on some nested property for a custom expectation use a function instead of a value:\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, JsonExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(JsonExtension)\n\ndescribe('A test', () => {\n  beforeEach(() => {\n    letBe.expectedObject = {\n      id: (value) => { expect(value).to.be.a('integer').above(0) }  // <-- custom expectation\n      order: {\n        products: [\n          oranges: 1\n        ]\n      }\n    }\n  })\n\n  it('expects the actual object not to have other properties that the ones in expectedProperties', () => {\n    expect(response.body).to.have.allPropertiesIn(expectedProperties)\n  })\n})\n```\n\nThis expectation block is useful to test for a text to match a regular expression and for a float to equal a constant\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, JsonExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(JsonExtension)\n\ndescribe('A test', () => {\n  beforeEach(() => {\n    letBe.expectedObject = {\n      description: (value) => { expect(description).to.match(/Product:/) }\n      price: (value) => { expect(price).to.be.closeTo(1, 0.001) }\n    }\n  })\n\n  it('expects an object property with a float and a text to satisfy custom assertions', () => {\n    expect(response.body).to.have.allPropertiesIn(expectedProperties)\n  })\n})\n```\n\n<a name=\"file-expectations\"></a>\n### File expectations\n\nAssert expectations on a file with\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, FileExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(FileExtension)\n\ndescribe('A test', () => {\n  it('expects a file to exist', () => {\n    expect('/path/to/someFile.txt').to.be.a.file\n  })\n\n  it('expects a file to have a content', () => {\n    expect('/path/to/someFile.txt').fileContents.to.match(/expression/)\n  })\n\n  it('expects a directory to exist', () => {\n    expect('/path/to/someDirectory').be.a.directory\n  })\n})\n```\n\nThe expected path\n\n```javascript\nexpect(path)\n```\n\ncan be a `String` or any other object that implements a `.toString()` method.\nParticularly it could be a `Path` object with a `path.toString()` method.\n\n\n### Disposable files helper\n\nTo create temporary files or directories during the tests use\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst { TmpDir } = require('o-testing-toolbox')\n\nbeforeEach(()=>{\n  const tmpDir = new TmpDir()\n  const stylesDir = tmpDir.createDir('styles/')\n  const scriptFile = tmpDir.createFile({ path: 'scripts/main.js', contents: 'const a = 1' })\n})\n```\n\nThe files and directories created through `TmpDir` are unique for each test execution and reside in the `/tmp` directory of your operative system and will be eventually discarded.\n\n\n<a name=\"skipping-slow-tests\"></a>\n### Skipping slow tests\n\nFor this extension to work first you need to install the following packages:\n\n```\nnpm install --save-dev mocha\nnpm install --save-dev chai\n```\n\nMocha reports tests that take longer to run than a configurable threshold.\n\nIn a regresion test you would like to run all tests but while you are developing a feature you may want to skip the slow ones.\n\nTo skip slow tests first run all the tests as usual to see which ones are reported to be slow\n\n```\nnpm test\n```\n\nOnce you have identified the slow ones on each slow test file include the `SlowTestsExtension` plugin for `chai`\n\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {SlowTestsExtension} = require('o-testing-toolbox')\n\nchai.use(SlowTestsExtension)\n```\n\nand replace the original test\n\n```javascript\ndescribe('...', () => {\n  it('this test is slow', () => {\n    // ...\n  })\n})\n```\n\nwith\n\n```javascript\ndescribe('...', () => {\n  slow.it('this test is slow', () => {\n    // ...\n  })\n})\n```\n\nIt's also possible to flag an entire group as slow:\n\n```javascript\nslow.describe('...', () => {\n  it('this test is slow', () => {\n    // ...\n  })\n\n  it('this one too', () => {\n    // ...\n  })\n})\n```\n\nFinally if you want to run the tests skipping the ones flagged as slow do\n\n```\nskip_slow=true npm test\n```\n\nTo run all the tests execute\n\n```\nnpm test\n```\n\nas usual.\n\n<a name=\"expected-code-styles\"></a>\n### Expected code styles\n\nFor this extension to work first you need to install the following packages:\n\n```\nnpm install --save-dev mocha\nnpm install --save-dev chai\n\nnpm install --save-dev eslint\nnpm install --save-dev eslint-config-standard\nnpm install --save-dev eslint-plugin-import\nnpm install --save-dev eslint-plugin-node\nnpm install --save-dev eslint-plugin-promise\"\nnpm install --save-dev eslint-plugin-standard\"\n```\n\nTo test that your source code complies with the coding standards and best practices create the test\n\n```javascript\nconst path = require('path')\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, SourceCodeExtension, SlowTestsExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(SourceCodeExtension)\nchai.use(SlowTestsExtension)\n\n\ndescribe('Coding style', () => {\n  before(() => {\n    letBe.eslintConfigFile = './utilities-config/.eslintrc.js'\n  })\n\n  slow.it('complies with standards', () => {\n    expect().to.complyWithCodingStyles({\n      eslintConfigFile: eslintConfigFile\n    })\n  })\n})\n```\n\nReplace the variable `letBe.eslintConfigFile` with your own `eslint` config file or delete it if you don't use a custom config file.\n\n\n<a name=\"expected-code-coverage\"></a>\n### Expected code coverage\n\nFor this extension to work first you need to install the following packages:\n\n```javascript\nnpm install --save-dev mocha@7\nnpm install --save-dev chai\n\nnpm install --save-dev nyc\n```\n\nNote that for this extension mocha version must be `mocha@7` due to breaking changes in version `mocha@8`\n\nTo test that the tests coverage is above an expected minimum create a new test file with the following contents:\n\n```javascript\nconst chai = require('chai')\nconst { expect } = require('chai')\nconst {LetBeExtension, SourceCodeExtension, SlowTestsExtension} = require('o-testing-toolbox')\n\nchai.use(LetBeExtension)\nchai.use(SourceCodeExtension)\nchai.use(SlowTestsExtension)\n\nconst linesCoverageTarget = 100\n\ndescribe('Testing suite covers', () => {\n    before( () => {\n        letBe.coveredLinesPercentage = linesCoverageTarget\n        letBe.thisFilename = path.basename(__filename)\n        letBe.fileExclusionPattern = `'**/${thisFilename}',`\n        letBe.mochaConfigFile = './utilities-config/.mocharc.json'\n        letBe.nycConfigFile = './utilities-config/nyc.config.json'    \n    })\n\n      slow.it(`${linesCoverageTarget}% of the lines of code`, () => {\n        expect().linesCoverage({\n          excluding: fileExclusionPattern,\n          mochaConfigFile: mochaConfigFile,\n          nycConfigFile: nycConfigFile\n        }).to.be.at.least(coveredLinesPercentage)\n    })\n})\n```\n\nNotes:\n\n- This test file is excluded for the coverage test otherwise it would create an infinite recursion.\n- Replace the variable `letBe.mochaConfigFile` and `nycConfigFile` with your own `mocha` and `nyc` config files or delete them if you don't use a custom config file.\n- The coverage test is always flagged as slow. You can skip running the tests with\n\n```\nskip_slow=true npm test\n```","readmeFilename":"README.md","homepage":"https://bitbucket.org/haijin-development/testing-toolbox"}