New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dmail/expect

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dmail/expect - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

dist/src/helper.test.js

46

dist/src/expectMatch/expectMatch.js

@@ -6,3 +6,3 @@ "use strict";

});
exports.expectUndefined = exports.expectNull = exports.expectFalse = exports.expectTrue = exports.createExpectFromMatcherFactory = exports.matchAny = exports.createMatcher = exports.expectMatch = void 0;
exports.expectUndefined = exports.expectNull = exports.expectFalse = exports.expectTrue = exports.expectNot = exports.matchNot = exports.matchAny = exports.createExpectFromMatcherFactory = exports.createMatcher = exports.expectMatch = void 0;

@@ -13,8 +13,16 @@ var _action = require("@dmail/action");

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// l'intérête principal de conserver un matcher et un expect séparé
// c'est de pouvoir, par la suite, exprimé qu'on souhaite matcher avec un matcher custom
// ce qui donne ceci :
// expectCalledWith(spy, 10)
// expectCalledWith(spy, matchClose(10))
// expectCalledWith(spy, matchBetween(5, 15))
var matchSymbol = Symbol();
var isMatcher = function isMatcher(value) {
return value !== null && value !== undefined && value.hasOwnProperty(matchSymbol);
};
var expectMatch = exports.expectMatch = function expectMatch(actual, expected) {
if (expected !== null && expected !== undefined && expected.hasOwnProperty(matchSymbol)) {
if (isMatcher(expected)) {
return expected[matchSymbol](actual);

@@ -31,9 +39,11 @@ }

var createMatcher = exports.createMatcher = function createMatcher(fn) {
return _defineProperty({}, matchSymbol, fn);
};
var matcher = {};
matcher[matchSymbol] = fn;
Object.defineProperty(matcher, "constructor", {
enumerable: false,
var matchAny = exports.matchAny = function matchAny() {
return createMatcher(function () {
return (0, _action.passed)();
/* istanbul ignore next */
value: function Matcher() {}
});
return matcher;
};

@@ -51,2 +61,20 @@

var matchAny = exports.matchAny = function matchAny() {
return createMatcher(function () {
return (0, _action.passed)();
});
};
var matchNot = exports.matchNot = function matchNot(expected) {
return createMatcher(function (actual) {
return expectMatch(actual, expected).then(function () {
return (0, _action.failed)("".concat((0, _uneval.uneval)(actual), " matching ").concat((0, _uneval.uneval)(expected)));
}, function () {
return (0, _action.passed)();
});
});
};
var expectNot = exports.expectNot = createExpectFromMatcherFactory(matchNot);
var expectTrue = exports.expectTrue = function expectTrue(actual) {

@@ -53,0 +81,0 @@ return expectMatch(actual, true);

@@ -106,4 +106,22 @@ "use strict";

pass();
},
"expectNot(null, null)": function expectNotNullNull(_ref12) {
var pass = _ref12.pass;
assertFailedWith((0, _expectMatch.expectNot)(null, null), "null matching null");
pass();
},
"expectNot(null, undefined)": function expectNotNullUndefined(_ref13) {
var pass = _ref13.pass;
assertPassedWith((0, _expectMatch.expectNot)(null, undefined));
pass();
},
"expectNot(10, customMatcherPassing": function expectNot10CustomMatcherPassing(_ref14) {
var pass = _ref14.pass;
var customMatcherPassing = (0, _expectMatch.createMatcher)(function () {
return (0, _action.passed)("foo");
});
assertFailedWith((0, _expectMatch.expectNot)(10, customMatcherPassing), "10 matching Matcher({})");
pass();
}
});
//# sourceMappingURL=expectMatch.test.js.map

4

package.json
{
"name": "@dmail/expect",
"version": "2.2.0",
"version": "2.3.0",
"license": "MIT",

@@ -24,3 +24,3 @@ "repository": {

"@dmail/spy": "0.0.2",
"@dmail/uneval": "0.0.1"
"@dmail/uneval": "1.0.0"
},

@@ -27,0 +27,0 @@ "devDependencies": {

@@ -12,5 +12,7 @@ // l'intérête principal de conserver un matcher et un expect séparé

const matchSymbol = Symbol()
const isMatcher = value =>
value !== null && value !== undefined && value.hasOwnProperty(matchSymbol)
export const expectMatch = (actual, expected) => {
if (expected !== null && expected !== undefined && expected.hasOwnProperty(matchSymbol)) {
if (isMatcher(expected)) {
return expected[matchSymbol](actual)

@@ -24,11 +26,26 @@ }

export const createMatcher = fn => ({
[matchSymbol]: fn
})
export const createMatcher = fn => {
const matcher = {}
matcher[matchSymbol] = fn
Object.defineProperty(matcher, "constructor", {
enumerable: false,
/* istanbul ignore next */
value: function Matcher() {}
})
return matcher
}
export const matchAny = () => createMatcher(() => passed())
export const createExpectFromMatcherFactory = matcherFactory => (actual, ...args) =>
expectMatch(actual, matcherFactory(...args))
export const matchAny = () => createMatcher(() => passed())
export const matchNot = expected =>
createMatcher(actual =>
expectMatch(actual, expected).then(
() => failed(`${uneval(actual)} matching ${uneval(expected)}`),
() => passed()
)
)
export const expectNot = createExpectFromMatcherFactory(matchNot)
export const expectTrue = actual => expectMatch(actual, true)

@@ -35,0 +52,0 @@ export const expectFalse = actual => expectMatch(actual, false)

@@ -8,3 +8,4 @@ import {

expectNull,
expectUndefined
expectUndefined,
expectNot
} from "./expectMatch.js"

@@ -14,3 +15,3 @@ import { createTest } from "@dmail/test"

import { createSpy } from "@dmail/spy"
import { failed } from "@dmail/action"
import { failed, passed } from "@dmail/action"

@@ -79,3 +80,16 @@ const assertPassedWith = (action, value) => {

pass()
},
"expectNot(null, null)": ({ pass }) => {
assertFailedWith(expectNot(null, null), "null matching null")
pass()
},
"expectNot(null, undefined)": ({ pass }) => {
assertPassedWith(expectNot(null, undefined))
pass()
},
"expectNot(10, customMatcherPassing": ({ pass }) => {
const customMatcherPassing = createMatcher(() => passed("foo"))
assertFailedWith(expectNot(10, customMatcherPassing), `10 matching Matcher({})`)
pass()
}
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc