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

Support for Stub#resolvesThis() #1368

Closed
kanehara opened this issue Mar 26, 2017 · 0 comments
Closed

Support for Stub#resolvesThis() #1368

kanehara opened this issue Mar 26, 2017 · 0 comments

Comments

@kanehara
Copy link

kanehara commented Mar 26, 2017

  • Sinon version : 2.1.0
  • Environment : Node 7.7.4

What did you expect to happen?
Stubs have #returnsThis() and #resolves() functionality but it is not possible to use either to return the Stub's context as a Promise. It would be nice to have a #resolvesThis() function in Stubs. For example, Mongoose's Model#save() method returns the saved Model object on success. Given the following function:

function save(userInfo) {
  const user = new User({
    ...userInfo
  });
  return user.save().catch(err => console.log(err));  
}

It would be nice to test that the saved user object actually contains all the info in userInfo via:

const stub = sinon.stub(User, "save");
stub.resolvesThis();
const savedUser = await save(mockUserInfo);
assert(savedUser.id === mockUserInfo.id);

#returnsThis returns the context but not as a promise and #resolves does not allow for returning the Stub context.

@kanehara kanehara changed the title Support for #resolvesThis() Support for Stub#resolvesThis() Mar 26, 2017
HugoMuller pushed a commit to HugoMuller/sinon that referenced this issue Aug 7, 2017
franck-romano pushed a commit to franck-romano/sinon that referenced this issue Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants