Answer the question
In order to leave comments, you need to log in
Can't figure out the shortcode?
I'm watching American courses, help me understand the short code
const expect = require('expect');
const request = require('supertest');
const {ObjectID} = require('mongodb');
const {app} = require('./../server');
const {Todo} = require('./../models/todo');
beforeEach((done) => {
Todo.remove({}).then(() => {
return Todo.insertMany(todos);
}).then(() => done());
});
У нас задействован Promise. Подскажите где тут у нас функция reject и resolve. Если нет resolve, где тогда catch? И что такое done?
Answer the question
In order to leave comments, you need to log in
Judging by the code, we are talking about testing.
You are describing the callback inside the beforeEach function .
Callback is a function that will be called at some point, conceived by the author, therefore the author also conceived that an argument will be passed inside this "callback" - another function. You called it done (because everyone calls it that, but instead of done , you could write qwe and the same would work).
Resolve and reject are names (also made up for convenience) of functions that you pass to then:
beforeEach((done) => {
Todo.remove({}).then(() => {
return Todo.insertMany(todos);
}).then(resolve, reject);
});
beforeEach((qwe) => {
Todo.remove({}).then(() => {
return Todo.insertMany(todos);
}).then(() => qwe());
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question