-
-
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 9 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,14 @@ 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'"); | ||
|
||
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.
One more test should be added here to the
assert
interface tests in order to verify the error message "the argument to property must be a string, number, or symbol". This test can closely resemble theexpect({a:1}).to.have.property(null);
test that you added on theexpect
interface, except using theassert
interface instead ofexpect
. (And using theerr
helper function, just like you've done in the previous two tests on theassert
interface).