A
A
alex4answ2020-09-11 11:27:45
JavaScript
alex4answ, 2020-09-11 11:27:45

How to test a function that generates a function?

Good afternoon, I'm studying testing, basic pure functions and so on do not raise questions, but I can't quite understand how to test such functions:

exports.isExistsValidator = (model, field) => {
  return async (value) => {
    const result = await model.findOne({ where: { [field]: value } });
    if (!result) {
      return Promise.reject(`${model.name} with ${field} = ${value} does not exists`);
    }
  }
};

How to test?, except that:
1. "Must return an asynchronous function"

So I should create a model stub?

PS What is the name of the function that returns the function? (does not fit the definition of a Higher Order Function)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question