3
I have a method in a service that removes items over 60 days from a list.
self.removerAntigas = function () {
var dataCorte = new Date();
var dataAux = dataCorte.getDate();
dataCorte.setDate(dataAux - 60);
itens.forEach(function (item) {
if (item.data <= dataCorte) {
itens.splice (itens.indexOf(item),1);
}
});
};
I also have the method that obtains all items from that list:
self.obterTodos = function (){
return itens;
}
And the method add:
self.adicionar = function () {
var item = {
data: new Date(),
latitude: 0,
longitude: 0,
conectado: true,
sincronizado: false
};
itens.push(item);
};
How can I write a test using Jasmine that tells me if I have removed the correct items from this list?
But in this case, I need to call the add by creating a fake list. With dates you would need to remove and dates you don’t need. My add already creates the "date" object with new Date(), in which case I want to pass the dates for it to create the list. This list comes from the service, it is manipulated directly there and does not contain items.
– Juliana
@Julianaprado in a test you must always have some list. As you did not give an example I created a fake. If you have a better example. Put here that I integrate or adapt the use of the code I gave...
– Sergio