I am new javascript. After I run my unit test. I got an error.
Test with static input
1) should return some1
0 passing (6ms)
1 failing
1) Test with static input should return some1:
TypeError: string is not a function
at Object.mock.fs.readFile (test/m1.js:9:14)
at Object.exports.readFile (arn.js:10:19)
at Context. (test/m1.js:24:5)
Here is my code .test/m1.js
var mock = require('mock')
var realB = require("../arn.js")
var test = require('unit.js');
var b = mock("../arn.js", {
fs: {
readFile: function (entry, callback) {
if (entry === "clowns.txt") {
callback(null,'some1');
}
}
}
}, require);
describe('Test with static input', function(){
it('should return some1', function(done){
b.readFile('clowns.txt', function(a){
test.value(a).match('some1');
done();
});
});
});
./arn.js
var fs = require('fs');
exports.readFile = function(entry,callback){
var cntent = fs.readFile(entry, "utf8", function(err, data) {
if (err) throw err;
//console.log(entry + " : " + data);
callback(data.substring(0,5));
});
}
I am not sure where I miss. Any help would be appreciated.
Sarit
Aucun commentaire:
Enregistrer un commentaire