Skip to content

Instantly share code, notes, and snippets.

@ebi
Created April 6, 2011 19:24
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 ebi/906335 to your computer and use it in GitHub Desktop.
Save ebi/906335 to your computer and use it in GitHub Desktop.
//Your example Class
function Person(name) {
this.name = name;
}
Person.prototype.greet = function () {
alert(this.name);
};
//The code using the class you want to test
function GreetCjno() {
var person = new Person('cjno');
person.greet();
}
//The actual test for JST
TestCase('ExampleTest', sinon.testCase({
'test that cjno gets greeted': function () {
Person = this.spy(Person);
this.spy(Person.prototype, 'greet');
GreetCjno();
Person.alwaysCalledWithExactly('cjno');
assertTrue(Person.prototype.greet.calledOnce);
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment