1

I'm testing some base.js (dean edwards base.js) code and want to test that some base function gets called with specific args. Our testing stack looks like js code, qunit, sinon. For example, I have:

var Foo = Base.extend({
    constructor: function () {
        //do constructor stuff
    },
    render: function (config) {
        config = config || {};

        //do rendery stuff with specified config
    }
});

var Bar = Foo.extend({
    render: function () {
        config = {a: 'a', b: 'b'};
        this.base(config);
    }
});

var b = (new Bar()).render();

So in the example above, I create a new instance of "Bar" and call the render method. The Bar render method specifies some config and passes that to the parent render method. Is there any way (using sinon.js) to spy on that base render call? I would typically do something like:

sinon.spy(b, 'render')

but that only gets me the initial call to render.

Jordan Kasper
  • 13,153
  • 3
  • 36
  • 55
Greg
  • 6,453
  • 9
  • 45
  • 61
  • possible duplicate of [Sinon Stub/Spy Using WithArgs Not Behaving As Expected](http://stackoverflow.com/questions/17302269/sinon-stub-spy-using-withargs-not-behaving-as-expected) – Paul Sweatte Apr 30 '14 at 18:13
  • Thanks @PaulSweatte, but I don't think the issues are related. I think my issue is more related to the specifics of testing base.js classes, rather than an issue with sinon. – Greg May 01 '14 at 18:43
  • Dean Edwards code was thoroughly explained by [John Resig](http://ejohn.org/blog/simple-javascript-inheritance/) and [its own documentation](http://base2.googlecode.com/svn/version/1.0.2/doc/base2.html#/doc/!base2). Sinon works with other classical inheritance implementations such as [ember](http://stackoverflow.com/questions/22677403/) and [backbone](http://stackoverflow.com/questions/10865364/), so I don't see why it wouldn't work in this instance. – Paul Sweatte May 01 '14 at 18:59

0 Answers0