| 8732 | } |
| 8733 | |
| 8734 | function SpyStrategyDispatcher(strategyArgs, matchersUtil) { |
| 8735 | const baseStrategy = new j$.SpyStrategy(strategyArgs); |
| 8736 | const argsStrategies = new StrategyDict(function () { |
| 8737 | return new j$.SpyStrategy(strategyArgs); |
| 8738 | }, matchersUtil); |
| 8739 | |
| 8740 | this.and = baseStrategy; |
| 8741 | |
| 8742 | this.exec = function (spy, args, invokeNew) { |
| 8743 | let strategy = argsStrategies.get(args); |
| 8744 | |
| 8745 | if (!strategy) { |
| 8746 | if (argsStrategies.any() && !baseStrategy.isConfigured()) { |
| 8747 | throw new Error( |
| 8748 | "Spy '" + |
| 8749 | strategyArgs.name + |
| 8750 | "' received a call with arguments " + |
| 8751 | j$.basicPrettyPrinter_(Array.prototype.slice.call(args)) + |
| 8752 | ' but all configured strategies specify other arguments.', |
| 8753 | ); |
| 8754 | } else { |
| 8755 | strategy = baseStrategy; |
| 8756 | } |
| 8757 | } |
| 8758 | |
| 8759 | return strategy.exec(spy, args, invokeNew); |
| 8760 | }; |
| 8761 | |
| 8762 | this.withArgs = function () { |
| 8763 | return { and: argsStrategies.getOrCreate(arguments) }; |
| 8764 | }; |
| 8765 | } |
| 8766 | |
| 8767 | function StrategyDict(strategyFactory, matchersUtil) { |
| 8768 | this.strategies = []; |