javascript - Matching an argument with a function in Jasmine -
i want perform custom assertion argument passed spied-on function call. can supply callback used within expectation against argument?
expect(my.method).tohavebeencalledwith(jasmine.argumentmatching(mycustomcallback), jasmine.any({})); ... jasmine.argumentmatching(mycustomcallback) pseudo code.
jasmine spy has property .calls, provides information number of calls, arguments particular calls, etc. take @ docs section - other tracking properties. depends on requirements 1 use, , in documentation described well, in general:
.calls.argsfor(n)- returns array of arguments n-th call.calls.allargs()- returns array of arrays of arguments calls.calls.mostrecent(),.calls.first()- return object in form:{ object: my, args: ['foo', 42'], returnvalue: undefined }.calls.all()- returns array of objects (like 1 above)
in general like:
spyon(my, 'method'); my.method('foo', 42); expect(my.method.calls.argsfor(0)).toequal(['foo', 42]);
Comments
Post a Comment