Closed Manstrike closed 1 year ago
We can for example introduce this kind of wrapper to match against a plain object
import { isEqual } from 'lodash';
function matches(expected: any, description?: string): Matcher<any> {
return new Matcher<any>(actual => isEqual(actual, expected), description || `${expected} should be expected`);
}
// ...
dependency.doSomething.calledWith(matches({ value: 'test value' })).mockReturnValue('plain object value tested');
I guess this works.
Thank you so match for reply! It actually works. I'm kinda feel disappointment about the fact it is not a "vanilla" feature, but I think solution is just fine for the first time) With minor refactoring, here is what i ended up with:
const matches: MatcherCreator<object> = (expected, description?: string) => {
return new Matcher((actual) => isEqual(actual, expected), description || `${expected} should be expected`);
};
Hi! Firstly, i'd like to thank you for this lib, as it adds functionality, that i missed so hard in vanilla
jest
(i've been usingjasmine
for a long time before) So, i've ran into a problem when usingcalledWith
. It appears,calledWith
completely ignores plain objects as condition:So, it looks like
.calledWith().mockReturnValue()
is being ignored when 'calledWith` condition is a plain object. Thank you in advance for your time!