Skip to content
This repository was archived by the owner on Nov 4, 2020. It is now read-only.

Commit b9bf8ff

Browse files
committed
Release 13.0.0
1 parent c8a5851 commit b9bf8ff

File tree

3 files changed

+36
-118
lines changed

3 files changed

+36
-118
lines changed

History.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
13.0.0 / 2017-09-05
2+
===================
3+
4+
* Removed `.enumerable` and `.enumerables`
5+
* Fixed `.match`ing on `Date`s
6+
* Added TypeScript definitions
7+
18
12.0.0 / 2017-08-28
29
===================
310

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "should",
33
"description": "test framework agnostic BDD-style assertions",
4-
"version": "12.0.0",
4+
"version": "13.0.0",
55
"author": "TJ Holowaychuk <tj@vision-media.ca>, Denis Bardadym <bardadymchik@gmail.com>",
66
"typings": "./should.d.ts",
77
"repository": {

should.js

Lines changed: 28 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* should - test framework agnostic BDD-style assertions
3-
* @version v12.0.0
3+
* @version v13.0.0
44
* @author TJ Holowaychuk <tj@vision-media.ca>, Denis Bardadym <bardadymchik@gmail.com>
55
* @link https://github.com/shouldjs/should.js
66
* @license MIT
@@ -1412,9 +1412,7 @@ Formatter.addType(new getGlobalType$1.Type(getGlobalType$1.OBJECT, getGlobalType
14121412
* MIT Licensed
14131413
*/
14141414
function isWrapperType(obj) {
1415-
return (
1416-
obj instanceof Number || obj instanceof String || obj instanceof Boolean
1417-
);
1415+
return obj instanceof Number || obj instanceof String || obj instanceof Boolean;
14181416
}
14191417

14201418
// XXX make it more strict: numbers, strings, symbols - and nothing else
@@ -1424,6 +1422,15 @@ function convertPropertyName(name) {
14241422

14251423
var functionName$1 = defaultFormat.functionName;
14261424

1425+
function isPlainObject(obj) {
1426+
if (typeof obj == "object" && obj !== null) {
1427+
var proto = Object.getPrototypeOf(obj);
1428+
return proto === Object.prototype || proto === null;
1429+
}
1430+
1431+
return false;
1432+
}
1433+
14271434
/*
14281435
* should.js - assertion library
14291436
* Copyright(c) 2010-2013 TJ Holowaychuk <tj@vision-media.ca>
@@ -3384,12 +3391,7 @@ var containAssertions = function(should, Assertion) {
33843391
}
33853392

33863393
this.assert(nextOther.done);
3387-
} else if (
3388-
obj != null &&
3389-
other != null &&
3390-
typeof obj == "object" &&
3391-
typeof other == "object"
3392-
) {
3394+
} else if (obj != null && typeof obj == "object" && other != null && typeof other == "object") {
33933395
//TODO compare types object contains object case
33943396
forEach(other, function(value, key) {
33953397
should(obj[key]).containDeepOrdered(value);
@@ -3449,12 +3451,7 @@ var containAssertions = function(should, Assertion) {
34493451
},
34503452
this
34513453
);
3452-
} else if (
3453-
obj != null &&
3454-
other != null &&
3455-
typeof obj == "object" &&
3456-
typeof other == "object"
3457-
) {
3454+
} else if (obj != null && other != null && typeof obj == "object" && typeof other == "object") {
34583455
// object contains object case
34593456
forEach(other, function(value, key) {
34603457
should(obj[key]).containDeep(value);
@@ -3500,62 +3497,9 @@ var propertyAssertions = function(should, Assertion) {
35003497
};
35013498
var obj = this.obj;
35023499
this.have.ownProperty(name);
3503-
should(Object.getOwnPropertyDescriptor(Object(obj), name)).have.properties(
3504-
desc
3505-
);
3506-
});
3507-
3508-
function processPropsArgs() {
3509-
var args = {};
3510-
if (arguments.length > 1) {
3511-
args.names = aSlice.call(arguments);
3512-
} else {
3513-
var arg = arguments[0];
3514-
if (typeof arg === "string") {
3515-
args.names = [arg];
3516-
} else if (Array.isArray(arg)) {
3517-
args.names = arg;
3518-
} else {
3519-
args.names = Object.keys(arg);
3520-
args.values = arg;
3521-
}
3522-
}
3523-
return args;
3524-
}
3525-
3526-
Assertion.add("enumerable", function(name, val) {
3527-
name = convertPropertyName(name);
3528-
3529-
this.params = {
3530-
operator:
3531-
"to have enumerable property " +
3532-
formatProp(name) +
3533-
(arguments.length > 1 ? " equal to " + i(val) : "")
3534-
};
3535-
3536-
var desc = { enumerable: true };
3537-
if (arguments.length > 1) {
3538-
desc.value = val;
3539-
}
3540-
this.have.propertyWithDescriptor(name, desc);
3500+
should(Object.getOwnPropertyDescriptor(Object(obj), name)).have.properties(desc);
35413501
});
35423502

3543-
Assertion.add(
3544-
"enumerables",
3545-
function(/*names*/) {
3546-
var args = processPropsArgs.apply(null, arguments);
3547-
3548-
this.params = {
3549-
operator: "to have enumerables " + args.names.map(formatProp)
3550-
};
3551-
3552-
var obj = this.obj;
3553-
args.names.forEach(function(name) {
3554-
should(obj).have.enumerable(name);
3555-
});
3556-
}
3557-
);
3558-
35593503
/**
35603504
* Asserts given object has property with optionally value. **On success it change given object to be value of property**.
35613505
*
@@ -3628,19 +3572,14 @@ var propertyAssertions = function(should, Assertion) {
36283572
}
36293573

36303574
var operator =
3631-
(props.length === 1
3632-
? "to have property "
3633-
: "to have " + (this.anyOne ? "any of " : "") + "properties ") +
3575+
(props.length === 1 ? "to have property " : "to have " + (this.anyOne ? "any of " : "") + "properties ") +
36343576
props.join(", ");
36353577

36363578
this.params = { obj: this.obj, operator: operator };
36373579

36383580
//check that all properties presented
36393581
//or if we request one of them that at least one them presented
3640-
this.assert(
3641-
missingProperties.length === 0 ||
3642-
(this.anyOne && missingProperties.length != names.length)
3643-
);
3582+
this.assert(missingProperties.length === 0 || (this.anyOne && missingProperties.length != names.length));
36443583

36453584
// check if values in object matched expected
36463585
var valueCheckNames = Object.keys(values);
@@ -3652,35 +3591,25 @@ var propertyAssertions = function(should, Assertion) {
36523591
valueCheckNames.forEach(function(name) {
36533592
var value = values[name];
36543593
if (eq$1(obj[name], value).length !== 0) {
3655-
wrongValues.push(
3656-
formatProp(name) + " of " + i(value) + " (got " + i(obj[name]) + ")"
3657-
);
3594+
wrongValues.push(formatProp(name) + " of " + i(value) + " (got " + i(obj[name]) + ")");
36583595
} else {
36593596
props.push(formatProp(name) + " of " + i(value));
36603597
}
36613598
});
36623599

3663-
if (
3664-
(wrongValues.length !== 0 && !this.anyOne) ||
3665-
(this.anyOne && props.length === 0)
3666-
) {
3600+
if ((wrongValues.length !== 0 && !this.anyOne) || (this.anyOne && props.length === 0)) {
36673601
props = wrongValues;
36683602
}
36693603

36703604
operator =
3671-
(props.length === 1
3672-
? "to have property "
3673-
: "to have " + (this.anyOne ? "any of " : "") + "properties ") +
3605+
(props.length === 1 ? "to have property " : "to have " + (this.anyOne ? "any of " : "") + "properties ") +
36743606
props.join(", ");
36753607

36763608
this.params = { obj: this.obj, operator: operator };
36773609

36783610
//if there is no not matched values
36793611
//or there is at least one matched
3680-
this.assert(
3681-
wrongValues.length === 0 ||
3682-
(this.anyOne && wrongValues.length != valueCheckNames.length)
3683-
);
3612+
this.assert(wrongValues.length === 0 || (this.anyOne && wrongValues.length != valueCheckNames.length));
36843613
}
36853614
});
36863615

@@ -3779,10 +3708,7 @@ var propertyAssertions = function(should, Assertion) {
37793708
return !has(obj, key);
37803709
});
37813710

3782-
var verb =
3783-
"to have " +
3784-
(this.onlyThis ? "only " : "") +
3785-
(keys.length === 1 ? "key " : "keys ");
3711+
var verb = "to have " + (this.onlyThis ? "only " : "") + (keys.length === 1 ? "key " : "keys ");
37863712

37873713
this.params = { operator: verb + keys.join(", ") };
37883714

@@ -3862,11 +3788,7 @@ var propertyAssertions = function(should, Assertion) {
38623788
while (properties.length) {
38633789
currentProperty = properties.shift();
38643790
this.params = {
3865-
operator:
3866-
"to have property by path " +
3867-
allProps.join(", ") +
3868-
" - failed on " +
3869-
formatProp(currentProperty)
3791+
operator: "to have property by path " + allProps.join(", ") + " - failed on " + formatProp(currentProperty)
38703792
};
38713793
obj = obj.have.property(currentProperty);
38723794
foundProperties.push(currentProperty);
@@ -4090,12 +4012,10 @@ var matchingAssertions = function(should, Assertion) {
40904012
);
40914013

40924014
if (notMatchedProps.length) {
4093-
this.params.operator +=
4094-
"\n not matched properties: " + notMatchedProps.join(", ");
4015+
this.params.operator += "\n not matched properties: " + notMatchedProps.join(", ");
40954016
}
40964017
if (matchedProps.length) {
4097-
this.params.operator +=
4098-
"\n matched properties: " + matchedProps.join(", ");
4018+
this.params.operator += "\n matched properties: " + matchedProps.join(", ");
40994019
}
41004020

41014021
this.assert(notMatchedProps.length === 0);
@@ -4112,12 +4032,7 @@ var matchingAssertions = function(should, Assertion) {
41124032
if (typeof res == "boolean") {
41134033
this.assert(res); // if it is just boolean function assert on it
41144034
}
4115-
} else if (
4116-
other != null &&
4117-
this.obj != null &&
4118-
typeof other == "object" &&
4119-
typeof this.obj == "object"
4120-
) {
4035+
} else if (typeof this.obj == "object" && this.obj != null && (isPlainObject(other) || Array.isArray(other))) {
41214036
// try to match properties (for Object and Array)
41224037
notMatchedProps = [];
41234038
matchedProps = [];
@@ -4132,9 +4047,7 @@ var matchingAssertions = function(should, Assertion) {
41324047
matchedProps.push(formatProp(key));
41334048
} catch (e) {
41344049
if (e instanceof should.AssertionError) {
4135-
notMatchedProps.push(
4136-
formatProp(key) + " (" + i(this.obj[key]) + ")"
4137-
);
4050+
notMatchedProps.push(formatProp(key) + " (" + i(this.obj[key]) + ")");
41384051
} else {
41394052
throw e;
41404053
}
@@ -4144,12 +4057,10 @@ var matchingAssertions = function(should, Assertion) {
41444057
);
41454058

41464059
if (notMatchedProps.length) {
4147-
this.params.operator +=
4148-
"\n not matched properties: " + notMatchedProps.join(", ");
4060+
this.params.operator += "\n not matched properties: " + notMatchedProps.join(", ");
41494061
}
41504062
if (matchedProps.length) {
4151-
this.params.operator +=
4152-
"\n matched properties: " + matchedProps.join(", ");
4063+
this.params.operator += "\n matched properties: " + matchedProps.join(", ");
41534064
}
41544065

41554066
this.assert(notMatchedProps.length === 0);

0 commit comments

Comments
 (0)