jest-matcher-called-on
Version:
Jest Custom Matcher Asserts the Context the Spy is Called On
37 lines (34 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
calledOn: function calledOn(received, context) {
var _this = this;
var instance = received.mock.instances[0];
var instanceProto = instance.constructor.prototype;
var contextProto = context.constructor.prototype;
var pass = void 0;
var message = void 0;
if (!instance) {
pass = false;
message = function message() {
_this.utils.matcherHint('.calledOn') + '\n\n' + 'Expected stub to be called on\n' + (' ' + _this.utils.printExpected(context) + '\n') + 'Received:\n' + (' ' + _this.utils.printReceived(instance));
};
} else if (Object.is(instanceProto, contextProto)) {
message = function message() {
return _this.utils.matcherHint('not.calledOn') + '\n\n' + 'Expected stub to not be called on\n' + (' ' + _this.utils.printExpected(context) + '\n') + 'Received:\n' + (' ' + _this.utils.printReceived(instance));
};
pass = true;
} else {
message = function message() {
return _this.utils.matcherHint('.calledOn') + '\n\n' + 'Expected stub to be called on\n' + (' ' + _this.utils.printExpected(context) + '\n') + 'Received:\n' + (' ' + _this.utils.printReceived(instance));
};
pass = false;
}
return {
pass: pass,
message: message
};
}
};