@fluffy-spoon/substitute
Advanced tools
Comparing version 1.74.0 to 1.75.0
@@ -1,8 +0,9 @@ | ||
import { Context } from "src/Context"; | ||
import { Context } from "../Context"; | ||
import { FunctionState } from "./FunctionState"; | ||
export declare type PropertyKey = string | number | symbol; | ||
export interface ContextState { | ||
onSwitchedTo?(context: Context): void; | ||
apply(context: Context, args: any[]): any; | ||
apply(context: Context, args: any[], matchingFunctionStates?: FunctionState[]): any; | ||
set(context: Context, property: PropertyKey, value: any): void; | ||
get(context: Context, property: PropertyKey): any; | ||
} |
@@ -14,5 +14,5 @@ import { ContextState, PropertyKey } from "./ContextState"; | ||
constructor(_getPropertyState: GetPropertyState, ...args: any[]); | ||
apply(context: Context, args: any[]): any; | ||
apply(context: Context, args: any[], matchingFunctionStates: FunctionState[]): any; | ||
set(context: Context, property: PropertyKey, value: any): void; | ||
get(context: Context, property: PropertyKey): any; | ||
} |
@@ -49,9 +49,11 @@ "use strict"; | ||
}); | ||
FunctionState.prototype.apply = function (context, args) { | ||
FunctionState.prototype.apply = function (context, args, matchingFunctionStates) { | ||
var e_1, _a, e_2, _b; | ||
var callCount = this._callCount; | ||
var hasExpectations = context.initialState.hasExpectations; | ||
var matchingFunctionStates = this._getPropertyState | ||
.recordedFunctionStates | ||
.filter(function (x) { return Utilities_1.areArgumentArraysEqual(x.arguments, args); }); | ||
if (!matchingFunctionStates) { | ||
matchingFunctionStates = this._getPropertyState | ||
.recordedFunctionStates | ||
.filter(function (x) { return Utilities_1.areArgumentArraysEqual(x.arguments, args); }); | ||
} | ||
if (hasExpectations) { | ||
@@ -58,0 +60,0 @@ callCount = matchingFunctionStates |
@@ -64,5 +64,6 @@ "use strict"; | ||
this._callCount = 0; | ||
var matchingFunctionState = this._recordedFunctionStates.find(function (x) { return Utilities_1.areArgumentArraysEqual(x.arguments, args); }); | ||
if (matchingFunctionState) { | ||
return matchingFunctionState.apply(context, args); | ||
var matchingFunctionStates = this._recordedFunctionStates.filter(function (x) { return Utilities_1.areArgumentArraysEqual(x.arguments, args); }); | ||
if (matchingFunctionStates.length > 0) { | ||
var matchingFunctionState = matchingFunctionStates[0]; | ||
return matchingFunctionState.apply(context, args, matchingFunctionStates); | ||
} | ||
@@ -69,0 +70,0 @@ var functionState = new (FunctionState_1.FunctionState.bind.apply(FunctionState_1.FunctionState, __spread([void 0, this], args)))(); |
{ | ||
"name": "@fluffy-spoon/substitute", | ||
"version": "1.74.0", | ||
"version": "1.75.0", | ||
"description": "An NSubstitute port to TypeScript called substitute.js.", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/Index.js", |
@@ -1,2 +0,3 @@ | ||
import { Context } from "src/Context"; | ||
import { Context } from "../Context"; | ||
import { FunctionState } from "./FunctionState"; | ||
@@ -7,5 +8,5 @@ export type PropertyKey = string|number|symbol; | ||
onSwitchedTo?(context: Context): void; | ||
apply(context: Context, args: any[]): any; | ||
apply(context: Context, args: any[], matchingFunctionStates?: FunctionState[]): any; | ||
set(context: Context, property: PropertyKey, value: any): void; | ||
get(context: Context, property: PropertyKey): any; | ||
} |
@@ -36,8 +36,11 @@ import { ContextState, PropertyKey } from "./ContextState"; | ||
apply(context: Context, args: any[]) { | ||
apply(context: Context, args: any[], matchingFunctionStates: FunctionState[]) { | ||
let callCount = this._callCount; | ||
const hasExpectations = context.initialState.hasExpectations; | ||
const matchingFunctionStates = this._getPropertyState | ||
.recordedFunctionStates | ||
.filter(x => areArgumentArraysEqual(x.arguments, args)); | ||
if(!matchingFunctionStates) { | ||
matchingFunctionStates = this._getPropertyState | ||
.recordedFunctionStates | ||
.filter(x => areArgumentArraysEqual(x.arguments, args)); | ||
} | ||
if(hasExpectations) { | ||
@@ -44,0 +47,0 @@ callCount = matchingFunctionStates |
@@ -42,5 +42,9 @@ import { ContextState, PropertyKey } from "./ContextState"; | ||
const matchingFunctionState = this._recordedFunctionStates.find(x => areArgumentArraysEqual(x.arguments, args)); | ||
if(matchingFunctionState) { | ||
return matchingFunctionState.apply(context, args); | ||
const matchingFunctionStates = this._recordedFunctionStates.filter(x => areArgumentArraysEqual(x.arguments, args)); | ||
if(matchingFunctionStates.length > 0) { | ||
const matchingFunctionState = matchingFunctionStates[0]; | ||
return matchingFunctionState.apply( | ||
context, | ||
args, | ||
matchingFunctionStates); | ||
} | ||
@@ -47,0 +51,0 @@ |
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
169751
71
2302