Let's say I have a function that looks like this:
function a() {
this.foo = 'bar';
return 'foo';
}
When invoked as a constructor `new a()`, this function will return `{foo: 'bar'}`
When invoked as a function `a()`, this function will return "foo"
If I were to stub this function like so:
sinon.stub(window, 'a').returns('bar');
Then, invoking the function like `a()` would return "bar", and invoking the function as a constructor `new a()` would return an empty object.
Is there a way to force this stub of my `a` function to return a value when it is invoked with the `new` keyword? Something like:
sinon.stub(window, 'a').whenCalledWithNew().returns({bar: 'foo'});
So that when I do `new a()`, it would return `{bar: 'foo'}` instead of an empty object?
Thanks