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

Already on GitHub? Sign in to your account

expect(spy1).toHaveBeenCalledBefore(spy2) #201

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
6 participants

mrak commented Mar 16, 2012

added a matcher to determine if one spy was called before another one during the spec

+1. That's a useful feature!

Aside from the fact I've created issue #279 on being able to extend spies easy, in most ways checking order may be replaced with (strict variant is in comments):

var first = jasmine.createSpy('first')/*.andCallFake(function() {
    expect(second).not.toHaveBeenCalled();
    expect(third).not.toHaveBeenCalled();
})*/;
var second = jasmine.createSpy('second').andCallFake(function() {
    expect(first).toHaveBeenCalled();
    //expect(third).not.toHaveBeenCalled();
});
var third = jasmine.createSpy('third').andCallFake(function() {
    //expect(first).toHaveBeenCalled();
    expect(second).toHaveBeenCalled();
});

createSpy is easy-replaceable with spyOn

Contributor

infews commented May 28, 2013

This feels a little strange. Do you understand why the calls have to happen in a certain order? This feels a little like a test smell - bending the framework instead of uncovering a potential design problem.

Do you have a use case you can share?

+1, i'm surprised that this hasn't been added to jasmine yet.

I have a test case where I am testing a observer and want to assert that the "before" hook is definitively executed before the actual method i am observing.

It is important in cases like testing, if you properly call an API methods in proper order in your application (e.g. HTML5 canvas calls). May be @infews is right for most cases, and it is smarter to test the result of the calls rather their order, but in case of canvas tests it is nearly to impossible.

Owner

slackersoft commented Oct 2, 2013

We're looking at doing a refactor of spies and their matchers for 2.1. There is a story in tracker for this, which I've linked back to this pull request. https://www.pivotaltracker.com/story/show/40631373

@slackersoft slackersoft closed this Oct 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment