我的代码没有给出错误,只是我必须满足 eslint,因为它给出了错误 'err' 已在上部作用域中声明。 如何在我的代码中修复它。
describe('/GET/:ID', () => {
it('should Get the task by ID', (done) => {
const book = new Task({ task: 'The Lord of the Rings' });
book.save((err, task) => {
chai.request(server)
.get(`/task/${task.id}`)
.send(task)
.end((err, res) => {
expect(res).to.have.status(200);
done();
});
});
});
});
最佳答案
ESlint 警告您 variable shadowing ,并不是因为它会抛出错误或不起作用,只是因为有时它可能是无意的,从而导致意外的行为,例如假设您希望在 chai
回调中使用 book.save
中的 err
?
要解决此问题,只需使用更明确的命名约定,例如saveErr
/chaiErr
关于node.js - 'err' 已在上部范围中声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59841831/