The functions you are testing in backendScript currently rely on external data. This means that if you add data to your database at a later time it could cause your tests to fail unexpectedly. They could quite easily be converted to pure functions and then tested in a more structured, scale-able way. For example the suggest function:
function suggest(sugName) {
var result = dbKeys.filter(function(item) {
return item.startsWith(sugName);
});
return result;
}
Could be converted to:
function suggest(sugName, searchArray) {
var result = searchArray.filter(function(item) {
return item.startsWith(sugName);
});
return result;
}
Although this makes the function slightly harder to call, it allows easy exchanging of data: you could swap the database to an array of words and the function wouldn't break.
The functions you are testing in backendScript currently rely on external data. This means that if you add data to your database at a later time it could cause your tests to fail unexpectedly. They could quite easily be converted to pure functions and then tested in a more structured, scale-able way. For example the suggest function:
Could be converted to:
Although this makes the function slightly harder to call, it allows easy exchanging of data: you could swap the database to an array of words and the function wouldn't break.