Skip to content

Instantly share code, notes, and snippets.

@pateketrueke
Created January 17, 2018 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pateketrueke/941d7df47b2e49af07a14716432437ea to your computer and use it in GitHub Desktop.
Save pateketrueke/941d7df47b2e49af07a14716432437ea to your computer and use it in GitHub Desktop.
Patch sinon-stubs for v2

Given sources with similar content:

anySymbolHere.stub(anObject, stringRef, hoistedFn);
anySymbolHere.stub(anObject, 'anyMethodCallAsString', () => true);

Execute the following command in your terminal:

sed -i '' 's/.stub(\(.*\), \(.*\));/.stub(\1).callsFake(\2);/g' *.js

Note: ensure the glob for *.js matches the desired files you want modify!

Once done, you'll get something like this:

anySymbolHere.stub(anObject, stringRef).callsFake(hoistedFn);
anySymbolHere.stub(anObject, 'anyMethodCallAsString').callsFake(() => true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment