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

multiple instances of mocked objects #20

Closed
ghost opened this issue Apr 24, 2017 · 3 comments
Closed

multiple instances of mocked objects #20

ghost opened this issue Apr 24, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 24, 2017

Hi,
When I was trying out ts-mockito I noticed that the instance() method does not create different instances of the mocked Class.

For example I have a class User with a field id. When creating two mocked objects:

let mockedUser = mock(User);
let user1 = instance(mockedUser);
let user2 = instance(mockedUser);
if(user1.id === user2.id)
  return true;
else return false;

This code yields true. Am I using the instance method in the wrong way?

@michalstocki
Copy link
Contributor

instance() is a kind of getter for the instance object corresponding with the provided mock object. If you would like to get two mocks of the same class, just call mock() twice.

@NagRock
Copy link
Owner

NagRock commented Apr 24, 2017

Hi @bjverhoe, as @michalstocki mentioned instance() method gets instance from specific mock. Because all behaviors are defined for mock, you should get one instance per one mock.

let mockedUser1 = mock(User);
let mockedUser2 = mock(User); // create second mock
let user1 = instance(mockedUser1);
let user2 = instance(mockedUser2);
if(user1.id === user2.id)
  return true;
else
  return false;

Please reopen issue if something is still wrong.

@NagRock NagRock closed this as completed Apr 24, 2017
@ghost
Copy link
Author

ghost commented Apr 25, 2017

Hi @NagRock, thanks for the info!

johanblumenberg pushed a commit to johanblumenberg/ts-mockito that referenced this issue Aug 12, 2022
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

No branches or pull requests

2 participants