У меня есть объект с несколькими методами:
module.exports = {
auth: async function() {
// Load the key
const key = JSON.parse(fs.readFileSync("./keys/key.json").toString());
// Auth using the key
var auth;
try {
auth = await google.auth.fromJSON(key);
} catch (e) {
console.error(e);
}
// Add read / write spreadsheets scope to our auth client
auth.scopes = ["https://www.googleapis.com/auth/spreadsheets"];
// Create an instance of sheets to a scoped variable
try {
this.sheets = await google.sheets({ version: "v4", auth });
} catch (e) {
console.error(e);
}
},
writeSingleRow: async function(spreadsheetId, sheetName, values, index) {
// Create the resource for google sheets
const resource = {
values
};
// Write out to the spreadsheet
const res = await this.sheets.spreadsheets.values.update({
spreadsheetId: spreadsheetId,
range: `${sheetName}!A${index + 2}:D${values.length + 1 + index}`,
valueInputOption: "RAW",
resource: resource
});
//console.log("Updated spreadsheet!");
},
readSingleRow: async function(spreadsheetId, sheetName, row) {
const range = sheetName + "!" + "A" + row + ":" + "AU" + row;
try {
const response = (
await this.sheets.spreadsheets.values.get({
spreadsheetId: spreadsheetId,
range: range,
majorDimension: "ROWS",
valueRenderOption: "UNFORMATTED_VALUE", // TODO: Update placeholder value.
dateTimeRenderOption: "FORMATTED_STRING" // TODO: Update placeholder value.
})
).data;
// TODO: Change code below to process the `response` object:
return response;
} catch (err) {
console.error(err);
}
}
};
И я пытаюсь проверить каждый. Проблема заключается в том, что методам чтения и записи необходимо отправлять параметры, а способа, по-видимому, нет.
Вот что я пробовал:
//readSingleRow
describe("readSingleRow", () => {
it("should not throw and return an object with \'values\' property", (done) => {
expect(sheets.readSingleRow(spreadsheetId,sheetName,row)).to.not.throw();
done();
});
});
и
describe("readSingleRow", () => {
it("should not throw and return an object with \'values\' property", (done) => {
var values = sheets.readSingleRow(spreadsheetId,sheetName,row);
expect(values).to.be.an(object);
done();
});
});
Ничего не работает. Как я могу передать параметры этой функции?
В качестве альтернативы, если я нахожусь далеко от цели, то что я должен делать? Конечно, я должен иметь возможность просто проверить вызов функции с параметрами. Кажется довольно простым, если я не пропускаю какую-то монументальную особенность тестирования.