I have a function fulltest as follows in abc.js file.
fullTest: function (fileList, callback) {
async.eachOfLimit(fileList, 200, function (file, key, cb) {
var path = utils.files.relativePath(file);
file.relativePath = path;
var values = utils.type.getPathValues(file.relativePath);
// checks if sub/ses-id in filename matches with ses/sub directory file is saved
var pathValues = values[0];
var fileValues = values[1];
if (fileValues.sub !== null || fileValues.ses !== null){
if (fileValues.sub !== pathValues.sub){
self.issues.push(new Issue({
code: 57,
evidence: "File: " + file.relativePath + " is saved in incorrect subject directory as per sub-id in filename.",
file: file
}));
}
if (fileValues.ses !== pathValues.ses){
self.issues.push(new Issue({
code: 58,
evidence: "File: " + file.relativePath + " is saved in incorrect session directory as per ses-id in filename.",
file: file
}));
}
}
}
Now in another file testabc.js i want to test the functionality of above function i.e when sub and ses id mismatch in the filename.
hence the code is as follows:
var issues = [{code: 57}, {code: 58}];
var code57_seen = false;
var code58_seen = false;
it('should return if sub and ses doesnt match', function () {
var files = ['/sub-22/ses-1/func/sub-22_ses-1_task-rest_acq-prefrontal_physio.tsv.gz',
'/sub-22/ses-1/func/sub-23_ses-1_task-rest_acq-prefrontal_physio.tsv.gz', '/sub-22/ses-1/func/sub-22_ses-2_task-rest_acq-prefrontal_physio.tsv.gz', '/sub-25/ses-2/func/sub-22_ses-1_task-rest_acq-prefrontal_physio.tsv.gz'];
var callback = function (issues, summary) {
for (var i in issues) {
if (issues[i]['code'] === 57) {
code57_seen = true;
}
else if (issues[i]['code'] === 58) {
code58_seen = false;
}
}
assert(code57_seen);
assert(code58_seen);
console.log(issues[i]['code'] === 58);
};
// assert(validatorss.bids.fullTest(files, callback));
abc.fullTest(files, callback);
});
The github link to this file is http://ift.tt/2uwHd7w. I am not sure how this test should be written to test a function from another file. Can someone point what is the mistake i am doing or how i should approach at this problem ..?
Aucun commentaire:
Enregistrer un commentaire