I'm new to unit testing so maybe I have this all wrong, but it seems kind of useless. I want to reduce bugs and integrate some tests with a build process however I'm not seeing the benefit at the moment. How can I improve the quality of tests, like the one below?
/* script */
SetAttributes = function(el, attrs) {
/**
* @method simple for in loop to help with creating elements programmatically
* @param {object} el - HTMLElement attributes are getting added to
* @param {object} attrs - object literal with key/values for desired attributes
* @example SetAttributes(info,{
* 'id' : 'utswFormInfo'
* 'class' : 'my-class-name'
* });
*/
for (let key in attrs) {
if (attrs.hasOwnProperty(key)) {
el.setAttribute(key, attrs[key]);
}
}
return el;
};
/** \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ **/
/* unit test */
describe("SetAttributes is for setting multiple attributes at a single time.", function() {
/** SetAttributes */
it("should not be null because it returns an HTMLElement with newly added attributes.", function() {
expect(SetAttributes(document.createElement('div'), {
defer: true,
src: null,
type: 'text/javascript'
})).not.toBe(null);
});
it("should not be a number because it returns an HTMLElement with newly added attributes.", function() {
expect(SetAttributes(document.createElement('div'), {
defer: true,
src: null,
type: 'text/javascript'
})).not.toBe(0);
});
it("should not be a string because it returns an HTMLElement with newly added attributes.", function() {
expect(SetAttributes(document.createElement('div'), {
defer: true,
src: null,
type: 'text/javascript'
})).not.toBe('div');
});
it("should not be undefined because it returns an HTMLElement with newly added attributes.", function() {
expect(SetAttributes(document.createElement('div'), {
defer: true,
src: null,
type: 'text/javascript'
})).not.toBe(undefined);
});
it("should not be a false value because it returns an HTMLElement with newly added attributes.", function() {
expect(SetAttributes(document.createElement('div'), {
defer: true,
src: null,
type: 'text/javascript'
})).not.toBeFalsy();
});
});