Skip to content

Instantly share code, notes, and snippets.

@ebi
Created April 6, 2011 19:24

Revisions

  1. ebi created this gist Apr 6, 2011.
    27 changes: 27 additions & 0 deletions sinon_constructor_test_example.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    //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);
    }
    }));