i trying learn how unit test javascript file jasmine. @ time, have following
/dist/myjavascriptfile.min.js
function myclass() {} module.exports = myclass; myclass.prototype.test = function(msg) { console.log(msg); }; i want test functions in class using jasmine. in attempt this, have following:
/test/unit/myjavascriptfile.spec.js
describe('myclass', function() { beforeeach(function() { module('myclass'); }); describe('test', function () { it('should write message', function() { myclass.test('hello test.'); }); }); }); when attempt run these tests, gulp, error. error is:
failures: 1) myclass test should write message 1.1) typeerror: object not function my belief happening because /dist/myjavascriptfile.min.js or myclass not loaded dependency. thought doing module('myclass'); line. however, not see how .spec.js file or jasmine test runner know location of definition of myclass. doing wrong?
for testing gulp-jasmine i've includes js code tested specs using this:
// path relative specs location var somelibtotest = require('path/to/my/js/file'); as using here commonjs module syntax, can same way. works console tests, not browser.
Comments
Post a Comment