I learn javascript (yes, I know there are type- and coffeescript.). In an application which requires a function func(a, b) = () => {"a": a, "b": ...b }
, I wish to be able to NOT spread b in case it is not spreadable. Is there some property flag that allows this kind of check? I know Python has mutable and non-mutable types, but I have never seen such isMutable(arg)
as well. :-/
Application: Jest matcher toHaveBeenNthCalledWith
accepts arguments (nthCall, arg1, arg2, ....)
such that nthCall
is compulsory and ...args
are variadic, and allows the function below:
export const expectToHaveBeenNthCalledWith = (functionHandler, expectation) => {
expect(functionHandler).toHaveBeenNthCalledWith(
expectation.callIndex,
...expectation.args
);
};
The unit-test of such function is somewhat given below. It works, fine! But... I wish to to able NOT to embrace the arguments on an array. :-/
describe("expectTo", () => {
...
it(
'assert Nth call with argument',
() => {
const functionCaller = (functionCall, arg_1, arg_2) => {
functionCall(arg_1);
functionCall(arg_2);
}
const string_1 = "ackbar";
const string_2 = "Boba Fett";
const expectation_1 = {"callIndex": 1, "args": [string_1]};
const expectation_2 = {"callIndex": 2, "args": [string_2]};
const f = jest.fn();
functionCaller(f, string_1, string_2);
expectToHaveBeenNthCalledWith(f, expectation_1);
expectToHaveBeenNthCalledWith(f, expectation_2);
}
);
...
})