4
Javascript code has some interactions with html like this example:
function retornaListaDeItens(argument) {
return document.getElementsByClassName(argument);
}
I use the return of this function to perform operations in Javascript, performing the unit test using Jasmine ended up encountering the following scenario of doubts:
It is wrong to test this function?
It is possible to simulate my html to perform tests that make interactions with it?
The test structure uses the file itself Specrunner.html of Jasmine and has no contact with html where has the list of items to be returned in this example, it ends up hindering unit testing.
The structure looks something like this:
app
lib
--bootstrap
--jasmine
src
--css
--js
--teste.js
test
--testeSpec.js
index.html
The idea of testing is 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);
});
Solved your problem?
– durtto
Hello @durtto, well I studied good Javascript programming practices along with good testing practices and I found that much of what I was doing was not following these good practices, an example of this was to mix the search behavior on the screen along with some rules, well summing up separated my js making communication with the screen and my js actually making the business rule and performed the tests only in performing the business rules.
– Emanoel
Good Emanoel. I’m glad you study like big people. It helps the community. Try to do the following, if you have found the answer, write it here and do not leave the question unanswered, as you help people who are in the same situation. The Community thanks you.
– durtto
Hello @durtto, yes I intend to do that.
– Emanoel