测试learnyounode练习6时出现回调问题(使其模块化)
在测试 learnyounode(使其模块化)的练习 6 时,我的代码通过了所有测试,但只有一个测试并显示 TypeError:回调不是函数。
ACTUAL EXPECTED
────────────────────────────────────────────────────────────────────────────────
"CHANGELOG.md" == "CHANGELOG.md"
"LICENCE.md" == "LICENCE.md"
"README.md" == "README.md"
────────────────────────────────────────────────────────────────────────────────
✓
Submission results match expected
Error
✓
Additional module file exports a single function
✓
Additional module file exports a function that takes 3 arguments
✓
Additional module file handles errors properly
✓
Additional module file handles callback argument
✓
Additional module file returned two arguments on the callback function
✓
Additional module file returned an Array as the second argument of the
callback
data.dat
learnyounode.dat
w00t.dat
words.dat
✓
Additional module file correctly handles '.'-prefixed extension
✗
Your additional module file [mymodule.js] did not return an Array with the
correct number of elements as the second argument of the callback
# FAIL Your solution to MAKE IT MODULAR didn't pass. Try again!
─────────────────────────────────────────────────────────────────────────────
mymodule.js:
const fs = require('fs')
const path = require('path');
function extFunc(directory, ext, callbackFunc) {
fs.readdir(directory, function(err, files) {
if (err) {
console.log("Error")
return callbackFunc(err);
}
files.forEach(function(file) {
if (path.extname(file) === ext) {
console.log(file);
};
});
callbackFunc(err, files);
})
};
module.exports = extFunc;
make-it-modular.js
const extFunc = require('./mymodule');
const directory = process.argv[2];
const ext = '.' + process.argv[3];
extFunc(directory, ext);
如果我能得到一些关于为什么 mymodule.js 中的回调函数抛出此错误并导致我最终无法通过 learnyounode 测试套件的反馈,我将不胜感激。
While testing exercise 6 of learnyounode (Make It Modular) my code is passing all of the tests but one and showing a TypeError: callback is not a function.
ACTUAL EXPECTED
────────────────────────────────────────────────────────────────────────────────
"CHANGELOG.md" == "CHANGELOG.md"
"LICENCE.md" == "LICENCE.md"
"README.md" == "README.md"
────────────────────────────────────────────────────────────────────────────────
✓
Submission results match expected
Error
✓
Additional module file exports a single function
✓
Additional module file exports a function that takes 3 arguments
✓
Additional module file handles errors properly
✓
Additional module file handles callback argument
✓
Additional module file returned two arguments on the callback function
✓
Additional module file returned an Array as the second argument of the
callback
data.dat
learnyounode.dat
w00t.dat
words.dat
✓
Additional module file correctly handles '.'-prefixed extension
✗
Your additional module file [mymodule.js] did not return an Array with the
correct number of elements as the second argument of the callback
# FAIL Your solution to MAKE IT MODULAR didn't pass. Try again!
─────────────────────────────────────────────────────────────────────────────
mymodule.js:
const fs = require('fs')
const path = require('path');
function extFunc(directory, ext, callbackFunc) {
fs.readdir(directory, function(err, files) {
if (err) {
console.log("Error")
return callbackFunc(err);
}
files.forEach(function(file) {
if (path.extname(file) === ext) {
console.log(file);
};
});
callbackFunc(err, files);
})
};
module.exports = extFunc;
make-it-modular.js
const extFunc = require('./mymodule');
const directory = process.argv[2];
const ext = '.' + process.argv[3];
extFunc(directory, ext);
I'd be hugely grateful if I could get some feedback on why the callback function in mymodule.js is throwing this error and causing me to ultimately fail the learnyounode test suite.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论