NagRock / ts-mockito

Mocking library for TypeScript
MIT License
969 stars 93 forks source link

Captured arguments are changed by object changes #218

Open namse opened 2 years ago

namse commented 2 years ago

I found that captured action(or method)'s arguments are changed when I change the object that I passed as argument.

for example,

class A {
  foo(b) {
  }
}

const mockedA = mock(A);
const instanceA = instance(mockedA);
const argument = {};
instanceA.foo(argument);
argument.c = 5;
const [firstArg] = capture(mockedFoo.foo).last();
console.log(firstArg) // print { c: 5 } ! I expected it prints { } because I pass {}.

I guess captured argument should be serialized

NagRock commented 2 years ago

But what then if you would like to compare instances?