Is it allowed to extend SpyStrategy?

63 views
Skip to first unread message

Valerii Vasin

unread,
Mar 27, 2015, 5:16:05 PM3/27/15
to jasmi...@googlegroups.com
Hi,

We are moving from mocha + sinon to jasmine, and I found some cases that look weird after replacing with jasmine.

For example, using sinon stubs I could do smth like this:

Backbone.ajax.yieldsTo('success', { success: true });

When stub will be called - success callback of passed object will be executed with { success: true } as a result.

In Jasmine it's possible to do like this:
this.Backbone.ajax.and.callFake(function(obj) {
    obj.success({ success: true });
});

I view sources and found that also it's possible to do via extending SpyStrategy, like this:

beforeEach(function() {
  jasmine.SpyStrategy.prototype.yieldsTo = function(prop, response) {
      return this.callFake(function(obj) {
          if (typeof obj[prop] === 'function') {
              obj[prop](response);
          }
      });
  };
});

But I am not sure about this - because it's not mentioned in official documentation.

It seems like an API to provide other spy methods based on core methods.

Could I rely on extending SpyStrategy or not?

Thank you.

Gregg Van Hove

unread,
Mar 31, 2015, 11:12:16 AM3/31/15
to jasmi...@googlegroups.com
The `SpyStrategy` is an internal api and not intended for extension by users at this time. We'd like to have some way for users/plugins to extend the behavior of spies in ways similar to this. We aren't totally sure what that would look like at this point, but if you have any ideas, let us know.

Thanks for using jasmine!

-Gregg

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages