Created
May 22, 2012 16:38
-
-
Save kazu69/2770136 to your computer and use it in GitHub Desktop.
Sinon.js stabのsimple test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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