@dmail/expect
Advanced tools
Comparing version 2.4.1 to 2.5.1
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.expectUndefined = exports.expectNull = exports.expectFalse = exports.expectTrue = exports.expectNot = exports.matchNot = exports.matchAny = exports.createExpectFromMatcherFactory = exports.createMatcher = exports.expectMatch = void 0; | ||
exports.expectUndefined = exports.expectNull = exports.expectFalse = exports.expectTrue = exports.expectNot = exports.matchNot = exports.matchExactly = exports.matchAny = exports.createExpectFromMatcherFactory = exports.createMatcher = exports.expectMatch = void 0; | ||
@@ -25,3 +25,3 @@ var _action = require("@dmail/action"); | ||
var expectMatch = exports.expectMatch = function expectMatch(actual, expected) { | ||
var match = function match(actual, expected) { | ||
if (isMatcher(expected)) { | ||
@@ -38,2 +38,4 @@ return expected[matchSymbol](actual); | ||
var expectMatch = exports.expectMatch = match; | ||
var createMatcher = exports.createMatcher = function createMatcher(fn) { | ||
@@ -67,2 +69,8 @@ var matcher = {}; | ||
var matchExactly = exports.matchExactly = function matchExactly(expected) { | ||
return createMatcher(function (actual) { | ||
return match(actual, expected); | ||
}); | ||
}; | ||
var matchNot = exports.matchNot = function matchNot(expected) { | ||
@@ -69,0 +77,0 @@ return createMatcher(function (actual) { |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.expectPropertiesIncludingHidden = exports.expectPropertyNamesAllowingExtra = exports.expectPropertyNames = exports.expectPropertiesAllowingExtra = exports.expectProperties = exports.matchPropertyNamesAllowingExtra = exports.matchPropertyNames = exports.matchPropertiesAllowingExtra = exports.matchPropertiesIncludingHidden = exports.matchProperties = void 0; | ||
exports.expectPropertiesDeep = exports.expectPropertyNamesAllowingExtra = exports.expectPropertyNames = exports.expectPropertiesAllowingExtra = exports.expectPropertiesIncludingHidden = exports.expectProperties = exports.matchPropertiesDeep = exports.matchPropertyNamesAllowingExtra = exports.matchPropertyNames = exports.matchPropertiesAllowingExtra = exports.matchPropertiesIncludingHidden = exports.matchProperties = void 0; | ||
@@ -23,3 +23,5 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
_ref$extraMustBeEnume = _ref.extraMustBeEnumerable, | ||
extraMustBeEnumerable = _ref$extraMustBeEnume === void 0 ? true : _ref$extraMustBeEnume; | ||
extraMustBeEnumerable = _ref$extraMustBeEnume === void 0 ? true : _ref$extraMustBeEnume, | ||
_ref$propertyMatcher = _ref.propertyMatcher, | ||
propertyMatcher = _ref$propertyMatcher === void 0 ? _expectMatch.matchExactly : _ref$propertyMatcher; | ||
@@ -37,3 +39,3 @@ if (actual === null || actual === undefined) { | ||
if (actualPropertyNames.includes(name)) { | ||
propertyExpectations.push((0, _expectMatch.expectMatch)(actual[name], expected[name]).then(null, function (message) { | ||
propertyExpectations.push((0, _expectMatch.expectMatch)(actual[name], propertyMatcher(expected[name])).then(null, function (message) { | ||
return "".concat(name, " property mismatch: ").concat(message); | ||
@@ -124,7 +126,23 @@ })); | ||
var matchPropertiesDeep = exports.matchPropertiesDeep = function matchPropertiesDeep(expected) { | ||
return (0, _expectMatch.createMatcher)(function (actual) { | ||
return compareProperties(actual, expected, { | ||
allowExtra: false, | ||
propertyMatcher: function propertyMatcher(value) { | ||
if (value === null || _typeof(value) !== "object" && typeof value !== "function") { | ||
return (0, _expectMatch.matchExactly)(value); | ||
} | ||
return matchPropertiesDeep(value); | ||
} | ||
}); | ||
}); | ||
}; | ||
var expectProperties = exports.expectProperties = (0, _expectMatch.createExpectFromMatcherFactory)(matchProperties); | ||
var expectPropertiesIncludingHidden = exports.expectPropertiesIncludingHidden = (0, _expectMatch.createExpectFromMatcherFactory)(matchPropertiesIncludingHidden); | ||
var expectPropertiesAllowingExtra = exports.expectPropertiesAllowingExtra = (0, _expectMatch.createExpectFromMatcherFactory)(matchPropertiesAllowingExtra); | ||
var expectPropertyNames = exports.expectPropertyNames = (0, _expectMatch.createExpectFromMatcherFactory)(matchPropertyNames); | ||
var expectPropertyNamesAllowingExtra = exports.expectPropertyNamesAllowingExtra = (0, _expectMatch.createExpectFromMatcherFactory)(matchPropertyNamesAllowingExtra); | ||
var expectPropertiesIncludingHidden = exports.expectPropertiesIncludingHidden = (0, _expectMatch.createExpectFromMatcherFactory)(matchPropertiesIncludingHidden); | ||
var expectPropertiesDeep = exports.expectPropertiesDeep = (0, _expectMatch.createExpectFromMatcherFactory)(matchPropertiesDeep); | ||
//# sourceMappingURL=expectProperties.js.map |
@@ -20,11 +20,11 @@ "use strict"; | ||
var assertPassedWith = function assertPassedWith(action, value) { | ||
_assert2.default.deepEqual(action.getResult(), value); | ||
_assert2.default.equal(action.getState(), "passed"); | ||
}; | ||
var assertFailedWith = function assertFailedWith(action, value) { | ||
_assert2.default.deepEqual(action.getResult(), value); | ||
}; | ||
var assertFailedWith = function assertFailedWith(action, value) { | ||
_assert2.default.equal(action.getState(), "failed"); | ||
_assert2.default.deepEqual(action.getResult(), value); | ||
}; | ||
@@ -144,4 +144,30 @@ | ||
pass(); | ||
}, | ||
"expectPropertiesDeep() with similar objects": function expectPropertiesDeepWithSimilarObjects(_ref15) { | ||
var pass = _ref15.pass; | ||
assertPassedWith((0, _expectProperties.expectPropertiesDeep)({ | ||
user: { | ||
name: "dam" | ||
} | ||
}, { | ||
user: { | ||
name: "dam" | ||
} | ||
}), [[undefined]]); | ||
pass(); | ||
}, | ||
"expectPropertiesDeep() with unexpected deep value": function expectPropertiesDeepWithUnexpectedDeepValue(_ref16) { | ||
var pass = _ref16.pass; | ||
assertFailedWith((0, _expectProperties.expectPropertiesDeep)({ | ||
user: { | ||
name: "dam" | ||
} | ||
}, { | ||
user: { | ||
name: "seb" | ||
} | ||
}), "user property mismatch: name property mismatch: \"dam\" does not match \"seb\""); | ||
pass(); | ||
} | ||
}); | ||
//# sourceMappingURL=expectProperties.test.js.map |
{ | ||
"name": "@dmail/expect", | ||
"version": "2.4.1", | ||
"version": "2.5.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -14,4 +14,3 @@ // l'intérête principal de conserver un matcher et un expect séparé | ||
value !== null && value !== undefined && value.hasOwnProperty(matchSymbol) | ||
export const expectMatch = (actual, expected) => { | ||
const match = (actual, expected) => { | ||
if (isMatcher(expected)) { | ||
@@ -26,2 +25,4 @@ return expected[matchSymbol](actual) | ||
export const expectMatch = match | ||
export const createMatcher = fn => { | ||
@@ -42,2 +43,3 @@ const matcher = {} | ||
export const matchAny = () => createMatcher(() => passed()) | ||
export const matchExactly = expected => createMatcher(actual => match(actual, expected)) | ||
export const matchNot = expected => | ||
@@ -44,0 +46,0 @@ createMatcher(actual => |
import { failed, all, any } from "@dmail/action" | ||
import { | ||
matchAny, | ||
matchExactly, | ||
expectMatch, | ||
@@ -14,3 +15,3 @@ createMatcher, | ||
expected, | ||
{ allowExtra = false, extraMustBeEnumerable = true } | ||
{ allowExtra = false, extraMustBeEnumerable = true, propertyMatcher = matchExactly } | ||
) => { | ||
@@ -32,3 +33,3 @@ if (actual === null || actual === undefined) { | ||
propertyExpectations.push( | ||
expectMatch(actual[name], expected[name]).then( | ||
expectMatch(actual[name], propertyMatcher(expected[name])).then( | ||
null, | ||
@@ -100,6 +101,23 @@ message => `${name} property mismatch: ${message}` | ||
export const matchPropertiesDeep = expected => | ||
createMatcher(actual => | ||
compareProperties(actual, expected, { | ||
allowExtra: false, | ||
propertyMatcher: value => { | ||
if (value === null || (typeof value !== "object" && typeof value !== "function")) { | ||
return matchExactly(value) | ||
} | ||
return matchPropertiesDeep(value) | ||
} | ||
}) | ||
) | ||
export const expectProperties = createExpectFromMatcherFactory(matchProperties) | ||
export const expectPropertiesIncludingHidden = createExpectFromMatcherFactory( | ||
matchPropertiesIncludingHidden | ||
) | ||
export const expectPropertiesAllowingExtra = createExpectFromMatcherFactory( | ||
matchPropertiesAllowingExtra | ||
) | ||
export const expectPropertyNames = createExpectFromMatcherFactory(matchPropertyNames) | ||
@@ -109,4 +127,3 @@ export const expectPropertyNamesAllowingExtra = createExpectFromMatcherFactory( | ||
) | ||
export const expectPropertiesIncludingHidden = createExpectFromMatcherFactory( | ||
matchPropertiesIncludingHidden | ||
) | ||
export const expectPropertiesDeep = createExpectFromMatcherFactory(matchPropertiesDeep) |
@@ -6,3 +6,4 @@ import { | ||
expectPropertyNamesAllowingExtra, | ||
expectPropertiesIncludingHidden | ||
expectPropertiesIncludingHidden, | ||
expectPropertiesDeep | ||
} from "./expectProperties.js" | ||
@@ -14,9 +15,9 @@ import { createTest } from "@dmail/test" | ||
const assertPassedWith = (action, value) => { | ||
assert.deepEqual(action.getResult(), value) | ||
assert.equal(action.getState(), "passed") | ||
assert.deepEqual(action.getResult(), value) | ||
} | ||
const assertFailedWith = (action, value) => { | ||
assert.deepEqual(action.getResult(), value) | ||
assert.equal(action.getState(), "failed") | ||
assert.deepEqual(action.getResult(), value) | ||
} | ||
@@ -104,3 +105,16 @@ | ||
pass() | ||
}, | ||
"expectPropertiesDeep() with similar objects": ({ pass }) => { | ||
assertPassedWith(expectPropertiesDeep({ user: { name: "dam" } }, { user: { name: "dam" } }), [ | ||
[undefined] | ||
]) | ||
pass() | ||
}, | ||
"expectPropertiesDeep() with unexpected deep value": ({ pass }) => { | ||
assertFailedWith( | ||
expectPropertiesDeep({ user: { name: "dam" } }, { user: { name: "seb" } }), | ||
`user property mismatch: name property mismatch: "dam" does not match "seb"` | ||
) | ||
pass() | ||
} | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
255426
3714