-
-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4.x.x Complete Migration Guide #781
Comments
I accidentally sent this issue while editing it. Current Status: This issue has just been updated (Sept. 6, 2016 - 10:13PM GMT-3) with every commit on the Since we've got a holiday in Brazil this Wednesday, I may be finishing this before the weekend. |
Don't forget to check out the draft |
@keithamus thanks for the link! I'll take a look at it. Currently I'm using |
This is done! 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 Special thanks to @vieiralucas for helping me finish this. |
Thanks for this amazing work @lucasfcosta |
Will try to review after work! |
@lucasfcosta Thank you for the enormous effort in tracking all of this down and organizing it! Also thank you for the dancing pikachu. A quick review yielded the following:
|
@meeber thanks for the review! EDIT: Fixed! Thanks for the help Mr. @meeber, your feedback is always great and constructive! |
Doing a last review here, noticed a couple things:
|
@meeber done! Also, we could also a link on the README for the ones interested into the migration guide, I think it would be useful, what do you guys think? |
Hi @lucasfcosta You may want to update for this PR too: #868 and #872 |
Hi @DeeperX, thanks for your input. |
Updated today (May, 9th - 2017) with all the changes included in the We're finally ready 🎉 🎉 🎉 🎉 🎉 🎉 🎉 |
I've moved this guide into https://github.com/chaijs/chai/releases/tag/4.0.0, this means it'll show up the site by the next rebuild I think. Thanks so much @lucasfcosta for your awesome work here! |
4.x.x Complete Migration Guide
Hello everyone! I'm writing this to serve as a guide for the
4.x.x
version.To make this as complete as possible I'll include here every single new feature, breaking change and fix and their respective issues and Pull Requests. Bugs introduced and solved after the 3.5.0 released won't be here, since it does not matter for the new version.
I'll also add some examples on how to migrate old code or to use new features when talking about these kinds of changes.
Please let me know if I've forgotten anything 😄
Breaking Changes
We no longer support Node v0.10 and v0.12 (since their LTS has ended) (PRs: Drop support of node v0.10 #816, chore: update supported Node versions #901)
Instead of allowing the user to write the path of a property, now the deep flag performs a deep equality comparison when used with the
.property
assertion.If you want the old behavior of using the dot or bracket notation to denote the property you want to assert against you can use the new
.nested
flag. (Related Issues: Unexpected meaning ofdeep
flag inproperty
assertion #745, expect(array).to.not.include(obj) failing with constructors #743, PRs: Add.deep.property
for deep equality comparisons #758, Breaking: Rename.deep.property
to.nested.property
#757)Please notice that the old methods which used the old behavior of the
deep
flag on theassert
interface have been renamed. They all have had thedeep
word changed by thenested
word. If you want to know more about this please take a look at Breaking: Rename.deep.property
to.nested.property
#757.Previously,
expect(obj).not.property(name, val)
would throw an Error ifobj
didn't have a property namedname
. This change causes the assertion to pass instead.The
assert.propertyNotVal
andassert.deepPropertyNotVal
assertions were renamed toassert.notPropertyVal
andassert.notDeepPropertyVal
, respectively. (Related Issues: negated property(name, value) assertion #16, expect(array).to.not.include(obj) failing with constructors #743, Add.deep.property
for deep equality comparisons #758)You can now use the
deep
flag for the.include
assertion in order to perform adeep
equality check to see if something is included on thetarget
.Previously,
.include
was using strict equality (===
) for non-negated property inclusion, butdeep
equality for negated property inclusion and array inclusion.This change causes the .include assertion to always use strict equality unless the deep flag is set.
Please take a look at this comment if you want to know more about it. (Related Issues: expect(array).to.not.include(obj) failing with constructors #743, PRs: Breaking: Fix
.include
to always use strict equality #760, Add.deep.include
for deep equality comparisons #761)Fix unstable behavior of the
NaN
assertion. Now we use the suggested ES6 implementation.The new implementation is now more correct, strict and simple. While the old one threw false positives, the new implementation only checks if something is
NaN
(or not if the.not
flag is used) and nothing else. (Related Issues: NaN assertion is not strict enough #498, NaN assertion is inconsistent with the standard and IEEE754 #682, void 0 and undefined is NaN #681, PRs: handle NaN properly in assertions #508)Throw when calling
_super
onoverwriteMethod
if the method being overwritten isundefined
.Currently if the method you are trying to overwrite is not defined and your new method calls
_super
it will throw anError
.(Related Issues: Overwrite method default _super does not throw #467, PRs: Throw when calling _super on overwriteMethod if method is undefined #528)Before this change, calling
_super
would simply returnthis
.Now
showDiff
is turned on by default whenever theshowDiff
flag is anything other thanfalse
.This issue will mostly affect plugin creators or anyone that made extensions to the core, since this affects the
Assertion.assert
method. (Related Issues: New showDiff behaviour also depending on expected and actual values #574, PRs: No showDiff set on assert interface #515)The Typed Array types are now truncated if they're too long (in this case, if they exceed the
truncateThreshold
value on theconfig
). (Related Issues: Typed Arrays not truncated #441, PRs: Truncate Typed Arrays (#441) #576)The assertions:
within
,above
,least
,below
,most
,increase
,decrease
will throw an error if the assertion's target or arguments are not numbers. (Related Issues: expect(null).to.be.within(0,10) does not fail assertion #691, PRs: [WIP] Verify types on within and related assertions #692, Verify types on increase | decrease #796)Previously, expect(obj).not.ownProperty(name, val) would throw an Error if obj didn't have an own property (non-inherited) named name. This change causes the assertion to pass instead. (Related Issues: Refactor
.ownProperty
to leverage.property
#795, #, PRs: Breaking: Change.not.property(name, val)
behavior #744, RefactorownProperty
#810)*The
.empty
assertion will now throw when it is passed non-string primitives and functions (PRs: Fix 'empty' assertion called on null #763, Make 'empty' throw on non-string primitives and functions #812)Assertion subject (
obj
) changes when usingownProperty
orown.property
and thus enables chaining. (Related Issues: Change assertion subject when using ownProperty #281, PRs: Assertion subject (obj) changes when using ownProperty assertion #641)The
utils
(second argument passed to thechai.use
callback function) no longer exports thegetPathValue
function. If you want to use that please use thepathval
module, which is what chai uses internally now. (Related Issues: Chai Roadmap #457, Move pathval into its own module #737, PRs: Use external pathval module #830)The
.change
,.increase
, and.decrease
assertions changed from chainable method assertions to method assertions. They don't have any chaining behavior, and there's no generic semantic benefit to chaining them. (Related Issues:.change
,.increase
, and.decrease
wrong assertion type #917, PRs: fix: wrong assertion types #925)New Features
Throw when non-existent property is read. (Related Issues: Use ES6 Proxy to throw on non-existing assertions #407, Make proxies optional #766 PRs: Throw when non-existent property is read #721, Make proxies optional #770)
This is a potentially breaking change. Your build will fail if you have typos in your property assertions
Before
4.x.x
when using property assertions they would not throw an error if you wrote it incorrectly.The example below, for example, would pass:
Since this implementation depends on ES6
Proxies
it will only work on platforms that support it.This property can be enabled (default) or disabled through the
config.useProxy
property, for example:Add fix suggestions when accessing a nonexistent property in proxy mode. (Related Issues: Use levenshtein distance to suggest alternatives in proxy mode #771, PRs: Add fix suggestions when accessing a nonexistent property in proxy mode #782)
When a nonexistent property is accessed in proxy mode, Chai will compute the levenshtein distance to all possible properties in order to suggest the best fix to the user.
When non-chainable methods (including overwritten non-chainable methods) are used incorrectly an error will be thrown with a helpful error message. (PRs: Wrap non-chainable methods in proxies #789)
Add a new configuration setting that describes which keys will be ignored when checking for non-existing properties on an assertion before throwing an error.
Since this implementation depends on ES6
Proxies
it will only work on platforms that support it. Also, if you disableconfig.useProxy
, this setting will have no effect. *(Related Issues: Cannot console.log assertions because of proxies #765, PRs: Configurable proxy blacklist #774)Add script that registers should as a side-effect. (Related Issues: Add an ES6-friendly way to register "should" #594, Mocha hook to auto register should #693 PRs: Add script that registers should as a side-effect #604)
You can also register should via a
mocha
option:mocha --require chai/should
.The
change
assertion accepts a function as object. (Related Issues: Feature request: .change/.increases etc with a function for value #544, PRs: Change function for value #607)You can also assert for a delta using the
by
assertion alongside thechange
,increase
anddecrease
assertions. (Related Issues: Assert an increase/decrease by an amount (delta) #339, PRs: Change by delta (New Assertion) #621).keys
assertion can now operate onmap
s andset
s. (Related Issues: Add assertions for ES6 Maps and Sets #632, PRs: Keys for maps and sets #633, Deep flag support for keys assertion #668)Add compatibility with strict mode. (Related Issues: Error on strict mode #578, PRs: add compatibility with strict mode #665)
Add
does
andbut
as new no-op assertion. (Related Issues: Requesting "does" as a no-op assertion #700, Assert an increase/decrease by an amount (delta) #339 PRs: Change by delta (New Assertion) #621, Add .does as a no-op assertion, Fix #700 #701)Allow
use
to be imported using new ES6 module syntax. (Related Issues: "use" doesn't behave as expected as an ES6 named export #718, PRs: Fix chai.use as ES6 named export #724)You can also use
require
alongside the new ES6 destructuring feature:Add ordered flag for members assertion. (Related Issues: Add an assertion for same members where order is important #717, PRs: Add ordered flag for members assertions #728)
Add
.own
flag to.property
assertion. It does the same thing as.ownProperty
and cannot be used alongisde the new.nested
flag. (Related Issues: Refactor.ownProperty
to leverage.property
#795, PRs: RefactorownProperty
#810)Add
.deep
support to.property
assertion. (Related Issues: Refactor.ownProperty
to leverage.property
#795, PRs: RefactorownProperty
#810)The
.empty
assertion will now work with ES6 collections (PRs: Fix 'empty' assertion called on null #763, Make 'empty' throw on non-string primitives and functions #812, Makeempty
assertion work with es6 collections #814)Please notice that this assertion will throw an error when it is passed a
WeakMap
orWeakSet
.Add script that registers
should
as a side-effect. This change allows you to registershould
via a mocha option by using:mocha spec.js -r chai/register-should
and also allows you to register the testing style globally. (Issues: Mocha hook to auto register should #693, PRs: Add script that registers expect as a side-effect #868)Add script that registers
assert
as a side-effect. This change allows you to registerassert
via a mocha option by using:mocha spec.js -r chai/register-assert
(Issues: Mocha hook to auto register should #693, PRs: Add script that registers expect as a side-effect #868, Auto register side effects and Update documentation #872)Add script that registers
expect
as a side-effect. This change allows you to registerexpect
via a mocha option by using:mocha spec.js -r chai/register-expect
(Issues: Mocha hook to auto register should #693, PRs: Add script that registers expect as a side-effect #868, Auto register side effects and Update documentation #872)When the
length
assertion is chained directly off of an uninvoked method, it referencesfunction
's built-inlength
property instead of Chai'slength
assertion. This commit adds a guard to Chai methods to detect this problem and throw a helpful error message that advises the user on how to correct it. (Issues: .length(value) deprecation #684,length
as assertion =>lengthOf
#841, PRs: Un-deprecatelength
and add guard #897)Allows the
lockSsfi
flag to be set when creating new Assertion. This flag controls whether or not the givenssfi
flag should retain its current value, even as assertions are chained off of this object. This is usually set totrue
when creating a new assertion from within another assertion. It's also temporarily set totrue
before an overwritten assertion gets called by the overwriting assertion. (Issues: Question regarding stack trace. #878, Flag transfer problem in failed.include
assertion #904, PRs: Remove implementation frames from stack trace #922)The
nestedInclude
,deepNestedInclude
,ownInclude
anddeepOwnInclude
assertions and there negated pairs were added to theassert
interface. (Issues: Missing.nested.include
and.own.include
#905, PRs: assert: add nestedInclude, deepNestedInclude, ownInclude and deepOwnInclude #964)Bug Fixes
this
. (Related Issues:an
language chain affectslength
language chain? #562, .length(value) deprecation #684, chai-as-promised broken by change to addMethod and addProperty #723, PRs: addMethod returns a new assertion with flags copied over instead of this #642, Fix missing require() calls #660).members
assertion. (Related Issues: Fix wrong order of expected and actual values for members matcher #511, PRs: .members should show diff #702)same.members
to properly handle duplicates by treating each one as a unique member. (Related Issues: Handling of duplicates when comparing sets #590, PRs: Fix duplicate handling in members assertion #739)overwriteMethod
,overwriteProperty
,addChainableMethod
,overwriteChainableMethod
functions will return new assertion with flags copied over instead of this. (Related Issues:an
language chain affectslength
language chain? #562, addMethod returns a new assertion with flags copied over instead of this #642, Consistency with returning new Assertion instead of this #791, PRs: Return new assertion with flags copied over instead of this. Fix #791 #799)keys
assertions will now consider size of sets. (Related Issues:.not.have.keys
incorrectly failing #919, PRs: fix: make negated.keys
consider size of sets #924).keys
consider size of sets #924).include
assertion #904, PRs: Remove implementation frames from stack trace #922).include
assertion #904, PRs:.by
doesn't accept optionalmsg
parameter #916, Custom message not always respected #923)The text was updated successfully, but these errors were encountered: