Skip to content

Commit

Permalink
Merge b5a054f into df3b5ac
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Feb 8, 2020
2 parents df3b5ac + b5a054f commit db818fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 5 additions & 6 deletions lib/assertions.js
Expand Up @@ -277,13 +277,12 @@ module.exports = expect => {
);

expect.addAssertion(
'<object> [not] to have (enumerable|configurable|writable) property <string>',
'<object> to have (enumerable|configurable|writable) property <string>',
(expect, subject, key) => {
const descriptor = expect.alternations[0];
expect(
Object.getOwnPropertyDescriptor(subject, key)[descriptor],
'[not] to be truthy'
);
const attribute = expect.alternations[0];
const descriptor = Object.getOwnPropertyDescriptor(subject, key);
expect(descriptor, 'to be defined');
expect(descriptor[attribute], 'to be truthy');
return subject[key];
}
);
Expand Down
12 changes: 9 additions & 3 deletions test/assertions/to-have-property.spec.js
Expand Up @@ -29,11 +29,8 @@ describe('to have property assertion', () => {

it('asserts validity of property descriptor', () => {
expect(subject, 'to have enumerable property', 'a');
expect(subject, 'not to have enumerable property', 'enumFalse');
expect(subject, 'to have configurable property', 'a');
expect(subject, 'not to have configurable property', 'configFalse');
expect(subject, 'to have writable property', 'a');
expect(subject, 'not to have writable property', 'writableFalse');
});

it('throws when assertion fails', () => {
Expand Down Expand Up @@ -62,6 +59,15 @@ describe('to have property assertion', () => {
"to have writable property 'writableFalse'"
);
});

// Regression test
it('does not break when the object does not have the given property', function() {
expect(
() => expect({}, 'to have configurable property', 'foo'),
'to throw',
"expected {} to have configurable property 'foo'"
);
});
});

it('throws when the assertion fails', () => {
Expand Down

0 comments on commit db818fb

Please sign in to comment.