Вы почти сделали это правильно.Некоторые примечания для исправления теста:
Добавление возврата в заглушку startQueryExecution
Это необходимо, чтобы функция execute
выполнялась правильно для возврата обещания.
sinon.stub(athenaClient, "startQueryExecution").returns({ promise: () => Promise.resolve() });
Удалить заглушку для метода execute
Это реальный метод, который мы хотим протестировать, и мы вызываем его в следующей строке, поэтому мы не должны заглушать его,
sinon.stub(executeAthenaQueryCommand, "execute"); // remove this
sinon.assert.calledWith(executeAthenaQueryCommand.execute, SQL_COMMAND); // remove this
Итак, итоговый тестовый файл будет
describe("Executes a sql command in Athena", async done => {
...
it("the sqlCommand is sent to startQueryExecution", async () => {
...
sinon.stub(athenaClient, "startQueryExecution").returns({ promise: () => Promise.resolve() }); // add returns
const result = await executeAthenaQueryCommand.execute(SQL_COMMAND);
const expectedResult = {
QueryString: SQL_COMMAND,
QueryExecutionContext: {
Database: "default"
}
};
sinon.assert.calledWith(athenaClient.startQueryExecution, expectedResult);
});
after(() => {});
});