1.10.0 / 2014-11-10
The following changes are required if you are upgrading from the previous version:
- Users:
- No changes required
- Plugin Developers:
- Review
addChainableNoop
notes below.
- Review
- Core Contributors:
- Refresh
node_modules
folder for updated dependencies.
- Refresh
Noop Function for Terminating Assertion Properties
The following assertions can now also be used in the function-call form:
- ok
- true
- false
- null
- undefined
- exist
- empty
- arguments
- Arguments
The above list of assertions 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.
expect(true).to.be.true;
foo.should.be.ok;
This syntax is definitely aesthetically pleasing but, 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.
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.
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.
expect(true).to.be.true();
foo.should.be.ok();
These forms can also be mixed in any way, these are all functionally identical:
expect(true).to.be.true.and.not.false();
expect(true).to.be.true().and.not.false;
expect(true).to.be.true.and.not.false;
Plugin Authors
If you would like to provide this function-call form for your terminating assertion properties, there is a new function to register these types of asserts. Instead of using addProperty
to register terminating assertions, simply use addChainableNoop
instead; the arguments to both are identical. The latter will make the assertion available in both the attribute and function-call forms and should have no impact on existing users of your plugin.
Community Contributions
- #297 Allow writing lint-friendly tests. @joshperry
- #298 Add check for logging
-0
. @dasilvacontin - #300 Fix #299: the test is defining global variables @julienw
Thank you to all who took time to contribute!