Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kazu69
Created May 22, 2012 16:38
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 kazu69/2770136 to your computer and use it in GitHub Desktop.
Save kazu69/2770136 to your computer and use it in GitHub Desktop.
Sinon.js stabのsimple test
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Backbone + sinon simple tests</title>
<script type="text/javascript" src='http://documentcloud.github.com/underscore/underscore-min.js'></script>
<script type="text/javascript" src='http://documentcloud.github.com/backbone/backbone.js'></script>
<script type="text/javascript" src='http://sinonjs.org/releases/sinon-1.3.4.js'></script>
<script type="text/javascript">
var Foo = function() {};
Foo.prototype.bar = function(content){ console.log(content); }
var foo = new Foo();
foo.bar('this is foo') // -> this is foo
var stub = sinon.stub(foo, 'bar');
stub.withArgs('this is foo').returns('this is stab');
var res = foo.bar('this is foo'); // -> 'this is stab'
console.log(res);
stub.restore();
foo.bar('this is foo'); // -> this is foo
var baz = function(content){ console.log(content + ' : ' + content); }
var stub = sinon.stub(foo, 'bar', baz);
stub.withArgs('this is foo');
foo.bar('this is foo'); // -> this is foo : this is foo
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment