I need to write unit tests for the following JS function:
let converter = {};
converter.removeSelectedAttribute = function removeSelectedAttribute(element)
{
options = Array.from(element.options);
options.forEach(function (item, index) {
item.removeAttribute('selected');
});
}
module.exports = converter;
This function is supposed to take a select DOM element and remove the selected attribute from its options.
Currently, I am using Mocha for testing with the code below:
let converter = require('../../main/webapp/WEB-INF/js/helper.js')
var assert = require('assert');
describe('Function', function() {
describe('#removeSelectedAttribute()', function() {
it('should work', function() {
var selectedOption = [{}]
var options = [{}]
var element = { className: '', tag: 't', name:'a', id:'b', selectedOptions: selectedOption, options: options };
converter.removeSelectedAttribute(element);
});
});
});
However, I am encountering an error "TypeError: item.removeAttribute is not a function". I realize my approach might be incorrect and would appreciate any guidance on how to properly unit test this code. Any help would be greatly appreciated.