@@ -327,12 +327,18 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
var makeMatchersUtil = function() {
|
||||
var customEqualityTesters =
|
||||
runnableResources[currentRunnable().id].customEqualityTesters;
|
||||
return new j$.MatchersUtil({
|
||||
customTesters: customEqualityTesters,
|
||||
pp: makePrettyPrinter()
|
||||
});
|
||||
const cr = currentRunnable();
|
||||
|
||||
if (cr) {
|
||||
const customEqualityTesters =
|
||||
runnableResources[cr.id].customEqualityTesters;
|
||||
return new j$.MatchersUtil({
|
||||
customTesters: customEqualityTesters,
|
||||
pp: makePrettyPrinter()
|
||||
});
|
||||
} else {
|
||||
return new j$.MatchersUtil({ pp: j$.basicPrettyPrinter_ });
|
||||
}
|
||||
};
|
||||
|
||||
var expectationFactory = function(actual, spec) {
|
||||
@@ -863,7 +869,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
makeMatchersUtil
|
||||
);
|
||||
|
||||
var spyRegistry = new j$.SpyRegistry({
|
||||
|
||||
@@ -7,11 +7,6 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
};
|
||||
})();
|
||||
|
||||
var matchersUtil = new j$.MatchersUtil({
|
||||
customTesters: [],
|
||||
pp: j$.makePrettyPrinter()
|
||||
});
|
||||
|
||||
/**
|
||||
* @classdesc _Note:_ Do not construct this directly. Use {@link spyOn},
|
||||
* {@link spyOnProperty}, {@link jasmine.createSpy}, or
|
||||
@@ -19,19 +14,24 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
* @class Spy
|
||||
* @hideconstructor
|
||||
*/
|
||||
function Spy(name, originalFn, customStrategies, defaultStrategyFn) {
|
||||
function Spy(name, matchersUtil, optionals) {
|
||||
const { originalFn, customStrategies, defaultStrategyFn } = optionals || {};
|
||||
|
||||
var numArgs = typeof originalFn === 'function' ? originalFn.length : 0,
|
||||
wrapper = makeFunc(numArgs, function(context, args, invokeNew) {
|
||||
return spy(context, args, invokeNew);
|
||||
}),
|
||||
strategyDispatcher = new SpyStrategyDispatcher({
|
||||
name: name,
|
||||
fn: originalFn,
|
||||
getSpy: function() {
|
||||
return wrapper;
|
||||
strategyDispatcher = new SpyStrategyDispatcher(
|
||||
{
|
||||
name: name,
|
||||
fn: originalFn,
|
||||
getSpy: function() {
|
||||
return wrapper;
|
||||
},
|
||||
customStrategies: customStrategies
|
||||
},
|
||||
customStrategies: customStrategies
|
||||
}),
|
||||
matchersUtil
|
||||
),
|
||||
callTracker = new j$.CallTracker(),
|
||||
spy = function(context, args, invokeNew) {
|
||||
/**
|
||||
@@ -143,11 +143,11 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
function SpyStrategyDispatcher(strategyArgs) {
|
||||
function SpyStrategyDispatcher(strategyArgs, matchersUtil) {
|
||||
var baseStrategy = new j$.SpyStrategy(strategyArgs);
|
||||
var argsStrategies = new StrategyDict(function() {
|
||||
return new j$.SpyStrategy(strategyArgs);
|
||||
});
|
||||
}, matchersUtil);
|
||||
|
||||
this.and = baseStrategy;
|
||||
|
||||
@@ -176,9 +176,10 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
};
|
||||
}
|
||||
|
||||
function StrategyDict(strategyFactory) {
|
||||
function StrategyDict(strategyFactory, matchersUtil) {
|
||||
this.strategies = [];
|
||||
this.strategyFactory = strategyFactory;
|
||||
this.matchersUtil = matchersUtil;
|
||||
}
|
||||
|
||||
StrategyDict.prototype.any = function() {
|
||||
@@ -203,7 +204,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
var i;
|
||||
|
||||
for (i = 0; i < this.strategies.length; i++) {
|
||||
if (matchersUtil.equals(args, this.strategies[i].args)) {
|
||||
if (this.matchersUtil.equals(args, this.strategies[i].args)) {
|
||||
return this.strategies[i].strategy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
getJasmineRequireObj().SpyFactory = function(j$) {
|
||||
function SpyFactory(getCustomStrategies, getDefaultStrategyFn) {
|
||||
function SpyFactory(
|
||||
getCustomStrategies,
|
||||
getDefaultStrategyFn,
|
||||
getMatchersUtil
|
||||
) {
|
||||
var self = this;
|
||||
|
||||
this.createSpy = function(name, originalFn) {
|
||||
return j$.Spy(
|
||||
name,
|
||||
return j$.Spy(name, getMatchersUtil(), {
|
||||
originalFn,
|
||||
getCustomStrategies(),
|
||||
getDefaultStrategyFn()
|
||||
);
|
||||
customStrategies: getCustomStrategies(),
|
||||
defaultStrategyFn: getDefaultStrategyFn()
|
||||
});
|
||||
};
|
||||
|
||||
this.createSpyObj = function(baseName, methodNames, propertyNames) {
|
||||
|
||||
Reference in New Issue
Block a user