I am trying to learn how to unit test a JavaScript file with Jasmine. At this time, I have the following
/dist/MyJavaScriptFile.min.js
function MyClass() {}
module.exports = MyClass;
MyClass.prototype.test = function(msg) {
console.log(msg);
};
I want to test the functions in this class using Jasmine. In an attempt to do this, I have the following:
/test/unit/MyJavaScriptFile.spec.js
describe('MyClass', function() {
beforeEach(function() {
module('MyClass');
});
describe('Test', function () {
it('should write a message', function() {
MyClass.test('hello from the test.');
});
});
});
When I attempt to run these tests, from Gulp, I get an error. The error is:
Failures:
1) MyClass Test should write a message
1.1) TypeError: object is not a function
My belief is that this is happening because /dist/MyJavaScriptFile.min.js or MyClass is not loaded as a dependency. I thought I was doing that with the module('MyClass'); line. However, I do not see how the .spec.js file or the Jasmine test runner would know the location of the definition of MyClass. What am I doing wrong?
gulp-jasmine.