i'm starting use jasmine unit testing of javascript code, , discovered if define suite or spec via describe() or it() inside of prototype method of object, isn't recognized spec on specrunner html page.
is there way around this? because of code written via prototype objects/methods , if can't test inside of those, can't test , jasmine pretty useless me. also, if not, there unit-testing frameworks js work in prototype methods/etc?
you can test methods defined on objects' prototypes using jasmine. consider basic person object.
function person(name) { this._name = name; } person.prototype.getname = function() { return this._name; }; to test getname function, use following.
describe('person test suite', function() { it('tests getname', function() { var p = new person('joe'); expect(p.getname()).tobe('joe'); }); }); you can spy on method that's on object's prototype. example.
spyon(person.prototype, 'getname'); // call method. expect(person.prototype.getname).tohavebeencalled(); hope helps.
Comments
Post a Comment