JavaScript code has some html interactions like this example:
function retornaListaDeItens(argument) {
return document.getElementsByClassName(argument);
}
I use the return of this function to perform operations in JavaScript, performing unit tests using Jasmine I came across the following scenario of doubts:
Is it wrong to test this function?
Is it possible to simulate my html to perform tests that interact with it?
The test framework uses Jasmine's own SpecRunner.html file and has no contact with the html where it has the list of items to return in this example, making it difficult for unit tests.
The structure looks something like this:
app
lib
--bootstrap
--jasmine
src
--css
--js
--teste.js
test
--testeSpec.js
index.html
The test idea looks like this:
it("retorno de lista de itens não deve ser vazio", function() {
var item = "item";
var list = retornaListaDeItens(item);
console.log(list.length);
expect(list).not.toBeLessThan(0);
});