Skip to content

Commit

Permalink
feat(objects): add toHaveUndefined matcher
Browse files Browse the repository at this point in the history
closes #37
  • Loading branch information
jacobwardio authored and JamieMason committed Jan 30, 2017
1 parent 6f0e7d5 commit 443dc76
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Matcher | Example
[toHaveStringSameLengthAs](https://github.com/JamieMason/Jasmine-Matchers/blob/master/test/toHaveStringSameLengthAs.spec.js) | `expect(object).toHaveStringSameLengthAs(memberName, string);`
[toHaveStringShorterThan](https://github.com/JamieMason/Jasmine-Matchers/blob/master/test/toHaveStringShorterThan.spec.js) | `expect(object).toHaveStringShorterThan(memberName, string);`
[toHaveTrue](https://github.com/JamieMason/Jasmine-Matchers/blob/master/test/toHaveTrue.spec.js) | `expect(object).toHaveTrue(memberName);`
[toHaveUndefined](https://github.com/JamieMason/Jasmine-Matchers/blob/master/test/toHaveUndefined.spec.js) | `expect(object).toHaveUndefined(memberName);`
[toHaveWhitespaceString](https://github.com/JamieMason/Jasmine-Matchers/blob/master/test/toHaveWhitespaceString.spec.js) | `expect(object).toHaveWhitespaceString(memberName);`
[toHaveWholeNumber](https://github.com/JamieMason/Jasmine-Matchers/blob/master/test/toHaveWholeNumber.spec.js) | `expect(object).toHaveWholeNumber(memberName);`

Expand Down
21 changes: 16 additions & 5 deletions dist/jasmine-matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ module.exports = {
toHaveStringSameLengthAs: require('./toHaveStringSameLengthAs'),
toHaveStringShorterThan: require('./toHaveStringShorterThan'),
toHaveTrue: require('./toHaveTrue'),
toHaveUndefined: require('./toHaveUndefined'),
toHaveWhitespaceString: require('./toHaveWhitespaceString'),
toHaveWholeNumber: require('./toHaveWholeNumber'),
toStartWith: require('./toStartWith'),
Expand All @@ -564,7 +565,7 @@ module.exports = {
}
};

},{"./toBeAfter":18,"./toBeArray":19,"./toBeArrayOfBooleans":20,"./toBeArrayOfNumbers":21,"./toBeArrayOfObjects":22,"./toBeArrayOfSize":23,"./toBeArrayOfStrings":24,"./toBeBefore":25,"./toBeBoolean":26,"./toBeCalculable":27,"./toBeDate":28,"./toBeEmptyArray":29,"./toBeEmptyObject":30,"./toBeEmptyString":31,"./toBeEvenNumber":32,"./toBeFalse":33,"./toBeFunction":34,"./toBeGreaterThanOrEqualTo":35,"./toBeHtmlString":36,"./toBeIso8601":37,"./toBeJsonString":38,"./toBeLessThanOrEqualTo":39,"./toBeLongerThan":40,"./toBeNear":41,"./toBeNonEmptyArray":42,"./toBeNonEmptyObject":43,"./toBeNonEmptyString":44,"./toBeNumber":45,"./toBeObject":46,"./toBeOddNumber":47,"./toBeRegExp":48,"./toBeSameLengthAs":49,"./toBeShorterThan":50,"./toBeString":51,"./toBeTrue":52,"./toBeValidDate":53,"./toBeWhitespace":54,"./toBeWholeNumber":55,"./toBeWithinRange":56,"./toEndWith":57,"./toHaveArray":58,"./toHaveArrayOfBooleans":59,"./toHaveArrayOfNumbers":60,"./toHaveArrayOfObjects":61,"./toHaveArrayOfSize":62,"./toHaveArrayOfStrings":63,"./toHaveBoolean":64,"./toHaveCalculable":65,"./toHaveDate":66,"./toHaveDateAfter":67,"./toHaveDateBefore":68,"./toHaveEmptyArray":69,"./toHaveEmptyObject":70,"./toHaveEmptyString":71,"./toHaveEvenNumber":72,"./toHaveFalse":73,"./toHaveHtmlString":74,"./toHaveIso8601":75,"./toHaveJsonString":76,"./toHaveMember":77,"./toHaveMethod":78,"./toHaveNonEmptyArray":79,"./toHaveNonEmptyObject":80,"./toHaveNonEmptyString":81,"./toHaveNumber":82,"./toHaveNumberWithinRange":83,"./toHaveObject":84,"./toHaveOddNumber":85,"./toHaveString":86,"./toHaveStringLongerThan":87,"./toHaveStringSameLengthAs":88,"./toHaveStringShorterThan":89,"./toHaveTrue":90,"./toHaveWhitespaceString":91,"./toHaveWholeNumber":92,"./toStartWith":93,"./toThrowAnyError":94,"./toThrowErrorOfType":95}],11:[function(require,module,exports){
},{"./toBeAfter":18,"./toBeArray":19,"./toBeArrayOfBooleans":20,"./toBeArrayOfNumbers":21,"./toBeArrayOfObjects":22,"./toBeArrayOfSize":23,"./toBeArrayOfStrings":24,"./toBeBefore":25,"./toBeBoolean":26,"./toBeCalculable":27,"./toBeDate":28,"./toBeEmptyArray":29,"./toBeEmptyObject":30,"./toBeEmptyString":31,"./toBeEvenNumber":32,"./toBeFalse":33,"./toBeFunction":34,"./toBeGreaterThanOrEqualTo":35,"./toBeHtmlString":36,"./toBeIso8601":37,"./toBeJsonString":38,"./toBeLessThanOrEqualTo":39,"./toBeLongerThan":40,"./toBeNear":41,"./toBeNonEmptyArray":42,"./toBeNonEmptyObject":43,"./toBeNonEmptyString":44,"./toBeNumber":45,"./toBeObject":46,"./toBeOddNumber":47,"./toBeRegExp":48,"./toBeSameLengthAs":49,"./toBeShorterThan":50,"./toBeString":51,"./toBeTrue":52,"./toBeValidDate":53,"./toBeWhitespace":54,"./toBeWholeNumber":55,"./toBeWithinRange":56,"./toEndWith":57,"./toHaveArray":58,"./toHaveArrayOfBooleans":59,"./toHaveArrayOfNumbers":60,"./toHaveArrayOfObjects":61,"./toHaveArrayOfSize":62,"./toHaveArrayOfStrings":63,"./toHaveBoolean":64,"./toHaveCalculable":65,"./toHaveDate":66,"./toHaveDateAfter":67,"./toHaveDateBefore":68,"./toHaveEmptyArray":69,"./toHaveEmptyObject":70,"./toHaveEmptyString":71,"./toHaveEvenNumber":72,"./toHaveFalse":73,"./toHaveHtmlString":74,"./toHaveIso8601":75,"./toHaveJsonString":76,"./toHaveMember":77,"./toHaveMethod":78,"./toHaveNonEmptyArray":79,"./toHaveNonEmptyObject":80,"./toHaveNonEmptyString":81,"./toHaveNumber":82,"./toHaveNumberWithinRange":83,"./toHaveObject":84,"./toHaveOddNumber":85,"./toHaveString":86,"./toHaveStringLongerThan":87,"./toHaveStringSameLengthAs":88,"./toHaveStringShorterThan":89,"./toHaveTrue":90,"./toHaveUndefined":91,"./toHaveWhitespaceString":92,"./toHaveWholeNumber":93,"./toStartWith":94,"./toThrowAnyError":95,"./toThrowErrorOfType":96}],11:[function(require,module,exports){
// modules
var reduce = require('./lib/reduce');
var api = require('./api');
Expand Down Expand Up @@ -1405,14 +1406,24 @@ module.exports = function toHaveTrue(key, actual) {
},{"./toBeObject":46,"./toBeTrue":52}],91:[function(require,module,exports){
// modules
var toBeObject = require('./toBeObject');
var toHaveMember = require('./toHaveMember');

// public
module.exports = function toHaveUndefined(key, actual) {
return toBeObject(actual) && toHaveMember(key, actual) && typeof actual[key] === 'undefined';
};

},{"./toBeObject":46,"./toHaveMember":77}],92:[function(require,module,exports){
// modules
var toBeObject = require('./toBeObject');
var toBeWhitespace = require('./toBeWhitespace');

// public
module.exports = function toHaveWhitespaceString(key, actual) {
return toBeObject(actual) && toBeWhitespace(actual[key]);
};

},{"./toBeObject":46,"./toBeWhitespace":54}],92:[function(require,module,exports){
},{"./toBeObject":46,"./toBeWhitespace":54}],93:[function(require,module,exports){
// modules
var toBeObject = require('./toBeObject');
var toBeWholeNumber = require('./toBeWholeNumber');
Expand All @@ -1422,7 +1433,7 @@ module.exports = function toHaveWholeNumber(key, actual) {
return toBeObject(actual) && toBeWholeNumber(actual[key]);
};

},{"./toBeObject":46,"./toBeWholeNumber":55}],93:[function(require,module,exports){
},{"./toBeObject":46,"./toBeWholeNumber":55}],94:[function(require,module,exports){
// modules
var toBeNonEmptyString = require('./toBeNonEmptyString');

Expand All @@ -1434,7 +1445,7 @@ module.exports = function toStartWith(subString, actual) {
return actual.slice(0, subString.length) === subString;
};

},{"./toBeNonEmptyString":44}],94:[function(require,module,exports){
},{"./toBeNonEmptyString":44}],95:[function(require,module,exports){
// public
module.exports = function toThrowAnyError(actual) {
try {
Expand All @@ -1445,7 +1456,7 @@ module.exports = function toThrowAnyError(actual) {
}
};

},{}],95:[function(require,module,exports){
},{}],96:[function(require,module,exports){
// public
module.exports = function toThrowErrorOfType(type, actual) {
try {
Expand Down
1 change: 1 addition & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ module.exports = {
toHaveStringSameLengthAs: require('./toHaveStringSameLengthAs'),
toHaveStringShorterThan: require('./toHaveStringShorterThan'),
toHaveTrue: require('./toHaveTrue'),
toHaveUndefined: require('./toHaveUndefined'),
toHaveWhitespaceString: require('./toHaveWhitespaceString'),
toHaveWholeNumber: require('./toHaveWholeNumber'),
toStartWith: require('./toStartWith'),
Expand Down
8 changes: 8 additions & 0 deletions src/toHaveUndefined.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// modules
var toBeObject = require('./toBeObject');
var toHaveMember = require('./toHaveMember');

// public
module.exports = function toHaveUndefined(key, actual) {
return toBeObject(actual) && toHaveMember(key, actual) && typeof actual[key] === 'undefined';
};
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ module.exports = {
toHaveStringSameLengthAs: require('./toHaveStringSameLengthAs.spec'),
toHaveStringShorterThan: require('./toHaveStringShorterThan.spec'),
toHaveTrue: require('./toHaveTrue.spec'),
toHaveUndefined: require('./toHaveUndefined.spec'),
toHaveWhitespaceString: require('./toHaveWhitespaceString.spec'),
toHaveWholeNumber: require('./toHaveWholeNumber.spec'),
toStartWith: require('./toStartWith.spec'),
Expand Down
33 changes: 33 additions & 0 deletions test/toHaveUndefined.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// modules
var describeToHaveX = require('./lib/describeToHaveX');

// spec
describe('toHaveUndefined', function () {
describeToHaveX('toHaveUndefined', function () {
describe('when subject does NOT have a member at the given key', () => {
it('should deny', function () {
expect({}).not.toHaveUndefined('memberName');
expect(null).not.toHaveUndefined('memberName');
});
});
describe('when subject DOES have a member at the given key', () => {
describe('when subject IS undefined', function () {
it('should confirm', function () {
expect({
memberName: undefined
}).toHaveUndefined('memberName');
});
});
describe('when subject is NOT undefined', function () {
it('should deny', function () {
expect({
memberName: null
}).not.toHaveUndefined('memberName');
expect({
memberName: 'undefined'
}).not.toHaveUndefined('memberName');
});
});
});
});
});

0 comments on commit 443dc76

Please sign in to comment.