All I want is a dynamic unit test running on Linux/Debian.
I want to get an array of links from a website using "superagent" or whatever module can send a GET request, and then do some tests on each of these links (again sending GET request to each link) using "describe", "it".
I searched for loops in mocha & chai in stackoverflow but the answers assume you already have an array and want to test each of its values so you won't be needing to send GET request to get the array values before test.
my problem is, I don't even have that array to iterate over its values, the array should contain almost 100 links and first I need to get them by sending a GET request to a website (example.com), then I need to test content of each of these links.
test.js
var expect = require('chai').expect;
var request = require('request');
var superagent = require('superagent');
var cheerio = require('cheerio');
var uri = 'http://example.com';
function caller(schemaID){
url = uri + schemaID;
describe("schema "+schemaID, function schema() {
it("available", function schemaLoader(done) {
superagent.get(url)
.end(function(err, res) {
var $ = cheerio.load(res.res.text);
expect(true).to.be.true;
done();
});
});
});
}
superagent.get(uri).end(function(err, res) {
var $ = cheerio.load(res.res.text);
var array = [];
$('#tab-content1').find('a').each(function(){
array.push($(this).attr("href"));
})
array.forEach(val => {
caller(val);
});
});
When I run this in terminal:
mocha test.js
it does nothing!
How would Mocha test all 100 links after getting list of links from superagent?