파일을 읽는 함수를 만들려고하는데 내가 뭘 잘못하고 있는지 이해하지 못합니다. 오류가 발생합니다SyntaxError: Unexpected token )
function WordCount(){}
WordCount.prototype.readfile = function(file) {
fs.readFile(file, 'utf8', function (err, data)) {
if (err) throw err;
}
}
module.exports = WordCount;
테스트:
describe('wordCount',function(){
var wordCount;
beforeEach(function(){
wordcount = new WordCount
});
describe("When trying to read a file", function() {
it('will not throw an error when reading the file', function() {
expect(wordCount.readFile(reader)).not.toThrow(err);
});
it('will throw an error if a file is missing', function() {
expect(wordCount.readFile()).toThrow(err);
});
});
});
이 문자열에 오류가 있습니다 : fs.readFile(file, 'utf8', function (err, data)) {
, readfile의 콜백이 잘못되었습니다.
당신은 필요 fs.readFile(file, 'utf8', function (err, data){...});
내가 jshinter 또는 jslinter로 사용 IDE를 권장합니다. 이것은 일반적인 상황이며 대괄호와 ";"을 확인해야합니다. jslint 및 jshint는 버그에 대한 도움말입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다