Skip to content

Commit 26d53e9

Browse files
author
ChaiJs Bot
committed
(data): Auto build _data
1 parent 013c0ee commit 26d53e9

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_id":"chai-parentheses","_rev":"1-40edf0dc1576842822345f6e03dd65f8","name":"chai-parentheses","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"chai-parentheses","version":"0.0.1","description":"Extends Chai with lint-friendly terminating assertions","main":"./lib/index.js","scripts":{"lint":"standard","test":"run-s test:*","test:node":"mocha","test:chrome":"pw-test test/index.spec.js","test:firefox":"pw-test test/index.spec.js -b firefox"},"repository":{"type":"git","url":"git+https://github.com/achingbrain/dirty-chai.git"},"keywords":["chai","chai-plugin","browser","testing"],"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"MIT","bugs":{"url":"https://github.com/achingbrain/dirty-chai/issues"},"homepage":"https://github.com/achingbrain/dirty-chai","devDependencies":{"chai":"^4.0.0","chai-as-promised":"^7.0.0","mocha":"^8.3.2","npm-run-all":"^4.1.5","playwright-test":"^3.0.5","standard":"^16.0.3"},"gitHead":"a5ff93bdb4a7a5773d65122666365aab9fd251eb","_id":"chai-parentheses@0.0.1","_nodeVersion":"15.13.0","_npmVersion":"7.7.6","dist":{"integrity":"sha512-JRseBAAnALI9AKLjhrgCBh5KrSN5Kkl6CnVkmGEIpXPQzgjV/g1IUvuMUplQbxIq2IXMpq1yy8936+/CjFWP8A==","shasum":"69c316f556c9118e1d5354c42509ff2e7ab0ee7d","tarball":"https://registry.npmjs.org/chai-parentheses/-/chai-parentheses-0.0.1.tgz","fileCount":3,"unpackedSize":12020,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgh9BaCRA9TVsSAnZWagAA6HQQAKGPlfTlmQ4tvCEJztIj\nEp7sBncuNi5Sc6Y8iwE4UFpLHa0oU+nZ20hUP1j61wzg1H1uc05j8kNY9f+5\n7fnCvxqTefyuDCwVvd3R8rof8s0n8RndA0uap+qi7/8/tkBhGnpdZ8QsAOMW\nqDqBsJA4VLYqvZQas2/LSxPZmaxcVP2YWRh/p88tNEpEfdyM98ae21NfztvV\nd4MpSJT+7vaDVKVskMxQvXYSWeMymIfJhb82KNBIr3l94luSLIVsz9GPk95m\nJXdSRa+cSqcuh/6Xk0YhBtxGEkwKlPax6C/VeLx5bbnHrBZYi8v/xoDji20g\nt3cliG9/yAnQ4ixp5vXG8t9E50qalUKAQEgVCJ2ezhehnMff9vDzgwOe6yQV\nU3FIde6LnCI+U7rDHwAyF7I887URzGTNbqCiRAlERVXJNMR+E1MS/Jfi3rNL\nlkhXpQ0fYQ3SeZ+UTH2bmpd+X2GFuG4kugI8T649a2iKspknErESc3cGZdWl\n0GHVBF/z5YCce2k9G8pg8Ue+tPtQ3Pl/54PAr5JU5PERm3KuUzkXEbQh0p4J\n67QSYoJ6NZG5niS7G62XyzwDOrkk/8dUswBCx+ah4gTlKjBIm+NxpNFPf4Dn\nHdcSAyidwLev/X0emzzc+OQccAjCytxu+IDZUfE08lzY/cNIgVLsIjqNDVsK\nb3BV\r\n=PExv\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/chai-parentheses_0.0.1_1619513433599_0.8848307818604237"},"_hasShrinkwrap":false},"0.0.2":{"name":"chai-parentheses","version":"0.0.2","description":"Extends Chai with lint-friendly terminating assertions","main":"./lib/index.js","types":"./index.d.ts","scripts":{"lint":"standard","test":"run-s test:*","test:node":"mocha","test:chrome":"pw-test test/index.spec.js","test:firefox":"pw-test test/index.spec.js -b firefox"},"repository":{"type":"git","url":"git+https://github.com/achingbrain/dirty-chai.git"},"keywords":["chai","chai-plugin","browser","testing"],"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"MIT","bugs":{"url":"https://github.com/achingbrain/dirty-chai/issues"},"homepage":"https://github.com/achingbrain/dirty-chai","devDependencies":{"@types/chai":"^4.2.17","@types/chai-as-promised":"^7.1.3","mocha":"^8.3.2","npm-run-all":"^4.1.5","playwright-test":"^3.0.5","standard":"^16.0.3"},"gitHead":"44f2d0bcd66e9d29d9f55cf37a0aa6ba15802c76","_id":"chai-parentheses@0.0.2","_nodeVersion":"15.13.0","_npmVersion":"7.7.6","dist":{"integrity":"sha512-pdBOsH31vzWKYHr8JYTlsP+TFx7RTTm/2hQYbpxFd1WQ/X58ryrLBINRL2C1OWje8bi42NQqNZl2RooFPrsBqA==","shasum":"4bad83d4f67efcba3e1605b48f597dd1eba8e5fc","tarball":"https://registry.npmjs.org/chai-parentheses/-/chai-parentheses-0.0.2.tgz","fileCount":4,"unpackedSize":12757,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgh9Q7CRA9TVsSAnZWagAAv7EP/1A78VuAh6S310Y2525H\nQViL1lVPSJsgceZtYFa1Dz3d1MsBKDqkfq0XGf9EKZENQ04NMnvn2GF9j8Hu\nzlbKpKxpDr1kQjWtUc0xk9LqGE5j7Q/vcesmhkJkmtkzsLrzwU97P2h39yuo\n5xbN9lfTYThRt1kpusgTquwiVXwAya5Qg1MbKkkhACAj/PmsiB+lprsp8YrF\nC5oq53o44Ppinhh/cFvKOFDoPZ8NzXH2cdv056ivOzGspKfCClMEFz9zqWTX\nogLcB/sJw5YxELws80s0pzs7jT9lxWneDv9OoAsE/N7W5YkuvgmCM1ASugAm\nqA7HgjVuc2l7qlgWDqmusl3e6tJOxg6iViPozQb7B5/2/8T1z/VcFMMizwPa\nUo1hkSoQU8f4JB9nlzKMjJJ0RMGnvbR2v1YZaumh1uvGwD+kXU9dP+YkXPLc\nxE5nVRW0UwoS5bZYKDaSuaxFIjEDKgCifl72Lq6IFaRSbbcsUPy6afgrr1GM\n3UhIGoac3PUZqnCyE80w7LCyEE8aBkdFiPNCXQSpxtPW55KwXcp5oWKg38Gp\n/doI5i6km2b8HlD1Vlpjb63fF2aezTc+TMd03kTx7OpitMgflkyxs4v8CMfb\nLy6Q7V/vOeA4IL3SErVURDivjQL9yMUF24qiqa8ONN4rr9ojlkIHS3ZDYQpg\njJxX\r\n=YG1p\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/chai-parentheses_0.0.2_1619514426926_0.730985240287223"},"_hasShrinkwrap":false}},"time":{"created":"2021-04-27T08:50:33.598Z","0.0.1":"2021-04-27T08:50:33.750Z","modified":"2021-04-27T09:07:09.189Z","0.0.2":"2021-04-27T09:07:07.058Z"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"description":"Extends Chai with lint-friendly terminating assertions","homepage":"https://github.com/achingbrain/dirty-chai","keywords":["chai","chai-plugin","browser","testing"],"repository":{"type":"git","url":"git+https://github.com/achingbrain/dirty-chai.git"},"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"bugs":{"url":"https://github.com/achingbrain/dirty-chai/issues"},"license":"MIT","readme":"chai-parentheses\n==========\n\n> API-compatible fork of dirty-chai as it has problems working with modern bundlers\n\nFunction form for terminating assertion properties.\n\n## Install\n```\nnpm install chai-parentheses --save-dev\n```\n## Usage\n\n`chai-parentheses` is a chai [plugin](http://chaijs.com/plugins).\n\n```js\nvar chai = require('chai');\nvar parentheses = require('chai-parentheses');\nvar expect = chai.expect\n\nchai.use(parentheses);\n// ...\nexpect(true).to.be.true();\n```\n\n## Custom Error Messages\n\nWith this function form for terminating properties you can also provide custom error messages to show when the assertion fails. This works whether the assertion is somewhere mid-chain or at the end.\n\n```js\nexpect(true).to.be.true.and.not.false('Reason: Paradox');\nexpect(true).to.be.true('The fabric of logic has torn').and.not.false();\n```\n\n## Affected Assertions\n\nThe following built-in assertions are modified by this plugin to now use the function-call form:\n\n* ok\n* true\n* false\n* null\n* undefined\n* exist\n* empty\n* arguments\n* Arguments\n\n## Caveats\n\n### Always terminate with a function\n\nThese forms can also be mixed, but the chain must always be terminated in the function form or assertions up to that point in the chain will not execute.\n\n```js\nexpect(true).to.be.true.and.not.false();\nexpect(true).to.be.true().and.not.false();\n```\n\n### Chaining length/argument\n\nThis breaks both the `length` and `arguments` asserts when they are in the chain following any other assertion. To work around this limitation, do the `length` or `arguments` asserts first in the chain or just do multiple assertion statements.\n\n```js\nmyArray.should.exist.and.should.have.length(3); // Error: length is not a function\n\n// Do two assert statements instead\nmyArray.should.exist();\nmyArray.should.have.length(3);\n```\n\n### use with chai-as-promised\n\nIf you're using chai-as-promised, you should `.use` chai-as-promised before chai-parentheses:\n\n```js\nvar chai = require(\"chai\");\nvar chaiAsPromised = require(\"chai-as-promised\");\nvar parentheses = require(\"chai-parentheses\");\n\n\nchai.use(chaiAsPromised);\nchai.use(parentheses);\n```\n\n## Plugin Assertions\n\nThis plugin will also hook and convert any property assertions added by other Chai plugins. The only thing you need to do is make sure to load chai-parentheses before any other plugins so that it can get its hooks in place before the other plugins are loaded.\n\nFor example, if you load [sinon-chai](https://github.com/domenic/sinon-chai) after chai-parentheses, all of its property assertions will now be method assertions.\n\n```js\nspy.should.have.been.called();\nspy.should.have.been.calledOnce();\nspy.should.have.been.calledTwice();\n```\n\n## Why?\n\n[Chai](https://github.com/chaijs/chai) is probably one of the most popular assertion libraries in the node. It has over 400 dependents and is downloaded almost 500,000/month.\n\nFor stylistic reasons, Chai was designed so that any assertions that did not require parameters would simply assert on property access. This allowed those assertions to elide the empty parens that would be required if those assertions were methods.\n\nThis design decision has a pretty big impact on how much trust you can place in your tests, especially if you don't adhere strictly to TDD's red-green-refactor flow. For a detailed descent into why, read [Beware of libraries that assert on property access](https://github.com/moll/js-must#asserting-on-property-access).\n\nThere is also the problem of getting errors from linters like JSHint. If you are linting your test code, your linter will complain with an error something like \"Expected an assignment or function call and instead saw an expression.\" Since the linter doesn't know about the property getter it assumes this line has no side-effects, and throws a warning in case you made a mistake.\n\nSquelching these errors is not a good solution as test code is getting to be just as important as, if not more than, production code. Catching syntactical errors in tests using static analysis is a great tool to help make sure that your tests are well-defined and free of typos.\n\nThis plugin was written so that we can still take advantage of the large ecosystem of projects and plugins written with/for Chai, while still being able to trust your tests. It converts the built-in property assertions to method assertions, including any property assertions added by plugins.\n\nThe list of affected assertions, and many assertions added by plugins, are property getters that assert immediately on access. Because of that, they were written to be used by terminating the assertion chain with a property access.\n\n```js\nexpect(true).to.be.true;\nfoo.should.be.ok;\n````\n\nA better option was to provide a function-call form for these assertions so that the code's intent is more clear and the linters stop complaining about something looking off. This form is added in addition to the existing property access form and does not impact existing test code.\n\n```js\nexpect(true).to.be.true();\nfoo.should.be.ok();\n```\n","readmeFilename":"README.md"}

plugins/chai_parentheses.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
layout: plugin
3+
permalink: plugins/chai-parentheses/
4+
pluginName: chai-parentheses
5+
---
6+
7+
chai-parentheses
8+
==========
9+
10+
> API-compatible fork of dirty-chai as it has problems working with modern bundlers
11+
12+
Function form for terminating assertion properties.
13+
14+
## Install
15+
```
16+
npm install chai-parentheses --save-dev
17+
```
18+
## Usage
19+
20+
`chai-parentheses` is a chai [plugin](http://chaijs.com/plugins).
21+
22+
```js
23+
var chai = require('chai');
24+
var parentheses = require('chai-parentheses');
25+
var expect = chai.expect
26+
27+
chai.use(parentheses);
28+
// ...
29+
expect(true).to.be.true();
30+
```
31+
32+
## Custom Error Messages
33+
34+
With this function form for terminating properties you can also provide custom error messages to show when the assertion fails. This works whether the assertion is somewhere mid-chain or at the end.
35+
36+
```js
37+
expect(true).to.be.true.and.not.false('Reason: Paradox');
38+
expect(true).to.be.true('The fabric of logic has torn').and.not.false();
39+
```
40+
41+
## Affected Assertions
42+
43+
The following built-in assertions are modified by this plugin to now use the function-call form:
44+
45+
* ok
46+
* true
47+
* false
48+
* null
49+
* undefined
50+
* exist
51+
* empty
52+
* arguments
53+
* Arguments
54+
55+
## Caveats
56+
57+
### Always terminate with a function
58+
59+
These forms can also be mixed, but the chain must always be terminated in the function form or assertions up to that point in the chain will not execute.
60+
61+
```js
62+
expect(true).to.be.true.and.not.false();
63+
expect(true).to.be.true().and.not.false();
64+
```
65+
66+
### Chaining length/argument
67+
68+
This breaks both the `length` and `arguments` asserts when they are in the chain following any other assertion. To work around this limitation, do the `length` or `arguments` asserts first in the chain or just do multiple assertion statements.
69+
70+
```js
71+
myArray.should.exist.and.should.have.length(3); // Error: length is not a function
72+
73+
// Do two assert statements instead
74+
myArray.should.exist();
75+
myArray.should.have.length(3);
76+
```
77+
78+
### use with chai-as-promised
79+
80+
If you're using chai-as-promised, you should `.use` chai-as-promised before chai-parentheses:
81+
82+
```js
83+
var chai = require("chai");
84+
var chaiAsPromised = require("chai-as-promised");
85+
var parentheses = require("chai-parentheses");
86+
87+
88+
chai.use(chaiAsPromised);
89+
chai.use(parentheses);
90+
```
91+
92+
## Plugin Assertions
93+
94+
This plugin will also hook and convert any property assertions added by other Chai plugins. The only thing you need to do is make sure to load chai-parentheses before any other plugins so that it can get its hooks in place before the other plugins are loaded.
95+
96+
For example, if you load [sinon-chai](https://github.com/domenic/sinon-chai) after chai-parentheses, all of its property assertions will now be method assertions.
97+
98+
```js
99+
spy.should.have.been.called();
100+
spy.should.have.been.calledOnce();
101+
spy.should.have.been.calledTwice();
102+
```
103+
104+
## Why?
105+
106+
[Chai](https://github.com/chaijs/chai) is probably one of the most popular assertion libraries in the node. It has over 400 dependents and is downloaded almost 500,000/month.
107+
108+
For stylistic reasons, Chai was designed so that any assertions that did not require parameters would simply assert on property access. This allowed those assertions to elide the empty parens that would be required if those assertions were methods.
109+
110+
This design decision has a pretty big impact on how much trust you can place in your tests, especially if you don't adhere strictly to TDD's red-green-refactor flow. For a detailed descent into why, read [Beware of libraries that assert on property access](https://github.com/moll/js-must#asserting-on-property-access).
111+
112+
There is also the problem of getting errors from linters like JSHint. If you are linting your test code, your linter will complain with an error something like "Expected an assignment or function call and instead saw an expression." Since the linter doesn't know about the property getter it assumes this line has no side-effects, and throws a warning in case you made a mistake.
113+
114+
Squelching these errors is not a good solution as test code is getting to be just as important as, if not more than, production code. Catching syntactical errors in tests using static analysis is a great tool to help make sure that your tests are well-defined and free of typos.
115+
116+
This plugin was written so that we can still take advantage of the large ecosystem of projects and plugins written with/for Chai, while still being able to trust your tests. It converts the built-in property assertions to method assertions, including any property assertions added by plugins.
117+
118+
The list of affected assertions, and many assertions added by plugins, are property getters that assert immediately on access. Because of that, they were written to be used by terminating the assertion chain with a property access.
119+
120+
```js
121+
expect(true).to.be.true;
122+
foo.should.be.ok;
123+
````
124+
125+
A better option was to provide a function-call form for these assertions so that the code's intent is more clear and the linters stop complaining about something looking off. This form is added in addition to the existing property access form and does not impact existing test code.
126+
127+
```js
128+
expect(true).to.be.true();
129+
foo.should.be.ok();
130+
```

0 commit comments

Comments
 (0)