Sinon: stub(obj, 'meth', fn) has been removed, see documentation

Created on 2 Apr 2018  Â·  7Comments  Â·  Source: sinonjs/sinon

When I use the following code, I have an error:

let obj = {
    foo: function() {
    }
}
var stub = sinon.stub(obj , "foo", () => {});

stub(obj, 'meth', fn) has been removed, see documentation

I then check the documentation:

http://sinonjs.org/releases/v2.0.0/stubs/#var-stub--sinonstubobject-method-func

var stub = sinon.stub(object, "method", func);

Replaces object.method with a func, wrapped in a spy.

As usual, object.method.restore(); can be used to restore the original method.

I'm using sinon 4.3.

Most helpful comment

For those finding this by Google searching the error message, the updated docs are here: http://sinonjs.org/releases/v5.0.3/stubs/

It looks like the new form is stub(obj, 'meth').callsFake(fn):

~var stub = sinon.stub(object, "method", func);~
This has been removed from v3.0.0. Instead you should use
stub(obj, 'meth').callsFake(fn)
A codemod is available to upgrade your code

All 7 comments

Forget about is, for some reason Google seargh "sinon stub" point to the 2.0.0 documentation.

For those finding this by Google searching the error message, the updated docs are here: http://sinonjs.org/releases/v5.0.3/stubs/

It looks like the new form is stub(obj, 'meth').callsFake(fn):

~var stub = sinon.stub(object, "method", func);~
This has been removed from v3.0.0. Instead you should use
stub(obj, 'meth').callsFake(fn)
A codemod is available to upgrade your code

@mroderick: It's unfortunate that people end up creating issues due to our (?) SEO strategy, so maybe it's time to look at the suggestion I once had for fixing the out of date Google searches. I could start out with detailing the issue and a potential fix (as per our Twitter discussion of .. 2016?).

AFAI remember the suggested fix was doing something like Django, that foresakes some semantic correctness through canonical link manipulation to improve SEO by always having Google hits point to /latest. The details escape me ATM, but it was conceptually simple. It is just doing it using Jekyll that was the hurdle, AFAI can recall :-)

Would it be possible to have a banner at the top of old versions stating that these docs are outdated? That wouldn’t improve the search results, but at least it’s more obvious to visitors.

@mantoni Yeah, exactly one of the things that came up in my Twitter exchange with Morgan:


Btw, I have had second doubts about this due to some SEO concerns. I think we need another approach, ref this question: https://webmasters.stackexchange.com/questions/109113/versioned-pages-making-sure-google-points-to-the-current … which led me to this: https://webmasters.stackexchange.com/questions/99867/how-to-correctly-mark-up-different-versions-of-the-same-document-which-are-non-c …

Basically, I think a big improvement for better Google hits would be to do what Django does in their docs:https://webmasters.stackexchange.com/a/101534/11903 - use rel=canonical to basically wipe all but the latest versions from the index - have a small alert at the top alerting the user that they are looking at older docs.

I think that using banners and canonical (or noindex) would be a good start.

Ultimately, I'd like to have a better documentation website.

  • easier to manage, easier to contribute to (it's getting unwieldy with all the releases)
  • more examples, basically every method/property should have at least one good usage example
  • playground

as for today, i still come to this as the top google search result for stub(obj, 'meth', fn) has been removed, see documentation

Was this page helpful?
0 / 5 - 0 ratings