I am trying to add unit tests to an old vanilla JS project via Jasmine. I've read a little about using a specRunner.html page, but I've been hoping to include this as a git hook of some sort, instead of manually opening and confirming on a webpage.
This app runs by linking to all of the scripts in the index.html. There are no modules. It makes use of a global variable all the services are tacked onto to run the app.
Here's my current test set up, but I'm looking to improve it.
uat.js // this was existing already
globalVar.myUAT = (function () {
// this code requires anotherObject for it's getInstance()
})();
module.exports = globalVar.myUAT; // I had to add this
uat.spec.js // this is all new
describe('my tests', () => {
let anotherObject;
beforeEach(() => {
anotherObject = {...}; // I'm stubbing the object here
}
it('should instantiate', () => {
spyOn(anotherObject, 'method').and.callFake(...);
let uatClass = require('./uat.js');
let uat = uatFile.getInstance(anotherObject);
expect(uat).toBeTruthy();
}
});
What improvements can I make? I hate the stubbing of anotherObject in my beforeEach. Should I abandon this and just stick with the specRunner solution?