-
-
Notifications
You must be signed in to change notification settings - Fork 702
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
Changes from 8 commits
e167009
3f2ce29
335fd33
5fd4fa2
8ff7cb7
a078a6d
e1442d0
d58d2bf
84062b1
f9e5a68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1395,6 +1395,7 @@ describe('assert', function () { | |
var obj = { foo: { bar: 'baz' } }; | ||
var simpleObj = { foo: 'bar' }; | ||
var undefinedKeyObj = { foo: undefined }; | ||
var dummyObj = { a: '1' }; | ||
assert.property(obj, 'foo'); | ||
assert.property(obj, 'toString'); | ||
assert.propertyVal(obj, 'toString', Object.prototype.toString); | ||
|
@@ -1454,6 +1455,18 @@ describe('assert', function () { | |
err(function () { | ||
assert.property(undefined, 'a', 'blah'); | ||
}, "blah: Target cannot be null or undefined."); | ||
|
||
err(function () { | ||
assert.propertyVal(dummyObj, 'a', '2', 'blah'); | ||
}, "blah: expected { a: '1' } to have property 'a' of '2', but got '1'"); | ||
|
||
assert.doesNotThrow(function () { | ||
assert.nestedProperty({a:1}, '{a:1}'); | ||
}, Error, 'the argument to property must be a string when using nested syntax'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need to add this test actually. |
||
|
||
assert.throws(function () { | ||
assert.nestedProperty({a:1}, {'a':'1'}); | ||
}, Error, 'the argument to property must be a string when using nested syntax'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @solodynamo I'm sorry for making a mess, but I realized that what @meeber meant to suggest is for you to use the Notice that when you do that it will start to throw throw new AssertionError(flagMsg + 'the argument to property must be a string when using nested syntax'); But you need to do this: throw new AssertionError(
flagMsg + 'the argument to property must be a string when using nested syntax',
undefined,
ssfi
); I'm sorry again for the confusion I made. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, please pass a third argument to test if the custom message works. err(function () {
assert.nestedProperty({a:1}, {'a':'1'}, 'blah');
}, 'blah: the argument to property must be a string when using nested syntax'); |
||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's shouldn't be wrong to use But I agree with @meeber that we must try and be able to use own You can replace the ones you added on this PR with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure @vieiralucas . I have replaced them and also surely will open a seperate PR in future to replace the remaining. |
||
it('deepPropertyVal', function () { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1462,6 +1462,10 @@ describe('expect', function () { | |
err(function () { | ||
expect(undefined, 'blah').to.have.property("a"); | ||
}, "blah: Target cannot be null or undefined."); | ||
|
||
expect(function () { | ||
expect({a:1}).to.have.property(null); | ||
}).to.throw('the argument to property must be a string, number, or symbol'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use the |
||
}); | ||
|
||
it('property(name, val)', function(){ | ||
|
@@ -1755,6 +1759,10 @@ describe('expect', function () { | |
expect({ 'foo.bar': 'baz' }) | ||
.to.have.nested.property('foo.bar'); | ||
}, "expected { 'foo.bar': 'baz' } to have nested property 'foo.bar'"); | ||
|
||
expect(function () { | ||
expect({a:1}).to.have.nested.property({'a':'1'}); | ||
}).to.throw('the argument to property must be a string when using nested syntax'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use the |
||
}); | ||
|
||
it('nested.property(name, val)', function(){ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1407,6 +1407,16 @@ describe('should', function() { | |
|
||
({ 'foo.bar[]': 'baz'}).should.have.nested.property('foo\\.bar\\[\\]'); | ||
|
||
({a:1}).should.have.nested.property('a'); | ||
|
||
(function () { | ||
({a:1}).should.have.nested.property('{a:1}'); | ||
}).should.not.throw('the argument to property must be a string when using nested syntax'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove this test. We already test that |
||
|
||
(function () { | ||
({a:1}).should.have.nested.property({'a':'1'}); | ||
}).should.throw('the argument to property must be a string when using nested syntax'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use the |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more test should be added here to the |
||
err(function(){ | ||
({ 'foo.bar': 'baz' }).should.have.nested.property('foo.bar'); | ||
}, "expected { 'foo.bar': 'baz' } to have nested property 'foo.bar'"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this has an extra
space
.flagMsg
variable already has a trailing space