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

Allow making assertions on a sequence of calls #75

Closed
electricmonk opened this issue Dec 8, 2015 · 5 comments
Closed

Allow making assertions on a sequence of calls #75

electricmonk opened this issue Dec 8, 2015 · 5 comments

Comments

@electricmonk
Copy link

I'd like to propose a feature to support the following:

var visitor = sinon.spy();
[1,2].forEach(visitor);
expect(visitor).to.have.been.calledWith(1).then.calledWith(2).

If you're for it, I can try to contribute via PR

@domenic
Copy link
Collaborator

domenic commented Dec 8, 2015

What Sinon assertion does this correspond to?

@electricmonk
Copy link
Author

Sinon doesn't have this feature out of the box. Basically I'll be adding the then method, which would somehow iterate over spy.getCalls. Maybe each consecutive call to then will increment a flag, then I can do getCall(utils.flag('sinon-call-depth').getAndIncrement()) to get the next call on each then.

@domenic
Copy link
Collaborator

domenic commented Dec 8, 2015

Since Sinon doesn't have this feature, Sinon Chai should not. You should just use a series of assertions, instead of inventing a DSL.

@domenic domenic closed this as completed Dec 8, 2015
@electricmonk
Copy link
Author

The series of assertions would look like this:

var visitor = sinon.spy();
[1,2].forEach(visitor);
expect(visitor.getCall(0).args[0]).to.equal(1);
expect(visitor.getCall(1).args[0]).to.equal(2);

which is much less readable and more error prone. The purpose of a matcher library like Chai is to abstract away such implementation details in favor of well-described expectations. Why should the fact that this feature doesn't correspond to a function of Sinon mean that Sinon-Chai shouldn't expose it?

@electricmonk
Copy link
Author

For future reference, if anyone's interested, I ended up implementing this in a complementary plugin:
https://github.com/electricmonk/sinon-chai-in-order

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