Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It.isObjectWith partial deep comparison behavior is unexpected #110

Open
VinGarcia opened this issue Sep 4, 2018 · 3 comments · May be fixed by #128
Open

It.isObjectWith partial deep comparison behavior is unexpected #110

VinGarcia opened this issue Sep 4, 2018 · 3 comments · May be fixed by #128

Comments

@VinGarcia
Copy link

VinGarcia commented Sep 4, 2018

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 =]

@sescotti
Copy link

Facing the same issue here (using latest version)

@Kampfmoehre
Copy link

Did anybody come up with a solution yet?

@parisholley parisholley linked a pull request Aug 26, 2019 that will close this issue
@parisholley
Copy link

you can test out my solution with @parisholley/[email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants