typemoq
typemoq copied to clipboard
It.isObjectWith partial deep comparison behavior is unexpected
I was creating a test and I found that the isObjectWith function would be perfect for me since I did not want to test all attributes of my object, only the ones that concerned that specific test.
However, this object also had a sub-object with optional attributes (some of which I wanted to verify its presence, others I didn't), and this is what behaved differently than what I expected: It seems it will ignore attributes on the root of the object if they are not present, but won't ignore attributes of nested objects if they are not present.
I have created a minimal code example to ilustrate the problem:
import { It, Mock, Times } from 'typemoq';
function myFunc(object: {}) {
console.log('object', object);
}
const myFuncMock = Mock.ofInstance(myFunc);
myFuncMock
.setup((m) => m(It.isAny()))
.returns(() => Promise.resolve());
myFuncMock.object({ x:0, a: { b: 0, c: 0 } });
// Works
myFuncMock.verify((m) => m(
It.isObjectWith({ x:0 }),
), Times.once());
// Works
myFuncMock.verify((m) => m(
It.isObjectWith({ a: { b: 0, c: 0 } }),
), Times.once());
// Does not work:
myFuncMock.verify((m) => m(
It.isObjectWith({ a: { b: 0 } }),
), Times.once());
Is this the expected behavior?
Also, thanks in advance for your attention and for the great library =]
Facing the same issue here (using latest version)
Did anybody come up with a solution yet?
you can test out my solution with @parisholley/[email protected]