Skip to content
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

property assertion should only accept strings if nested, fixes #1043 #1044

Merged
merged 10 commits into from Oct 2, 2017
6 changes: 6 additions & 0 deletions lib/chai/core/assertions.js
Expand Up @@ -1765,6 +1765,12 @@ module.exports = function (chai, _) {
, obj = flag(this, 'object')
, ssfi = flag(this, 'ssfi');

if (typeof name !== 'string' && isNested) {
var msgPrefix = flag(this, 'message')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to define msgPrefix here; the value of flag(this, 'message') is already stored in the flagMsg variable from line 1764.

msgPrefix = msgPrefix ? msgPrefix + ': ' : ''
Copy link
Contributor

@meeber meeber Sep 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here on line 1770 is repeated on lines 1769 and 1778 (except with flagMsg); I'm thinking we can reduce duplication by removing all three of these and instead perform the operation a single time near the top after line 1766 where the variable declarations take place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is little duplication of logic here . We can remove msgPrefix and use flagMsg variable in its place and move the flagMsg = flagMsg ? flagMsg + ': ' : '' near the top as you suggested.

throw new AssertionError(msgPrefix + 'the argument to `property` must be a string')
}

if (isNested && isOwn) {
flagMsg = flagMsg ? flagMsg + ': ' : '';
throw new AssertionError(
Expand Down