I am performing a unit test on a function, and what I want is to simulate the communication with the DTA (that does not communicate with the database); For example: This is the function to which I want to perform the test ...
public add(a, b): Promise<any> {
return new Promise((resolve, reject) => {
this.queueDta.add(a, b)
.then(() => resolve({status: "created"}))
.catch(() => reject({code: "QUE01"}));
});
}
And then when doing the test, I want the add function that is connected to the DTA, to be executed but in a false way and return true; Create a stub to the DTA to modify the function, but take them differently, therefore, add the information to the database.
context("addToQueue", () => {
let data;
it("ADD", async () => {
const queueBns2 = new queueBns.QueueBns();
const queueDta2 = new queueDta.QueueDta();
let result2;
data = sandbox.stub(queueDta2, "add").value(true);
result2 = await queueBns2.add(1, 2);
//-- Aca irian los expect, para validar la funcion ---
});
});
I was looking for ways to instantiate the class in another way but I do not know, in what way I can modify that function and that the BNS uses the false function. Thank you for your cooperation. I'm pending:).