I am sometimes stubbing methods using the Arg class and want to know if the method is actually called using the received function. In the following code the first two pass but not the third:
import { Substitute, Arg } from "@fluffy-spoon/substitute"
interface CalculatorInterface {
add(a: number, b: number): number
subtract(a: number, b: number): number
divide(a: number, b: number): number
isEnabled: boolean
}
describe("Calc test", function() {
it("Can check recieved", function() {
const mockedCalculator = Substitute.for<CalculatorInterface>()
mockedCalculator.add(1, 2).returns(4)
console.log(mockedCalculator.add(1, 2)) //4
mockedCalculator.received(1).add(1, 2)
})
it("Can check recieved real args", function() {
const mockedCalculator = Substitute.for<CalculatorInterface>()
mockedCalculator.add(1, Arg.is(input => input === 2)).returns(4)
console.log(mockedCalculator.add(1, 2)) //4
mockedCalculator.received(1).add(1, 2)
})
it("Can not check substituted args", function() {
const mockedCalculator = Substitute.for<CalculatorInterface>()
mockedCalculator.add(1, Arg.is(input => input === 2)).returns(4)
console.log(mockedCalculator.add(1, 2)) //4
mockedCalculator.received(1).add(1, Arg.is(input => input === 2))
})
})
I know I can get around it by adding my own hook in the is and I understand if this is not supported but just wondering if it should/could be.
P.S. Enjoying using the library.
I am sometimes stubbing methods using the
Argclass and want to know if the method is actually called using thereceivedfunction. In the following code the first two pass but not the third:I know I can get around it by adding my own hook in the
isand I understand if this is not supported but just wondering if it should/could be.P.S. Enjoying using the library.