【发布时间】:2020-06-20 23:29:39
【问题描述】:
我有一个包含基本大查询操作的小类:
const { BigQuery } = require('@google-cloud/bigquery');
export default class BQ {
bigquery;
constructor(projectId, keyFilename) {
const options = {
projectId,
keyFilename,
autoRetry: true,
};
this.bigquery = new BigQuery(options);
}
async query(query) {
const options = {
query,
location: 'us',
};
const [job] = await this.bigquery.createQueryJob(options);
const [rows] = await job.getQueryResults();
return rows;
}
}
我正在尝试为 query 方法编写 mocha 单元测试。然而,我一直被困在 js 中创建模拟。 Sinon、沙箱、存根等有很多选项。我认为我需要存根一个实例属性,例如,
const bq = new BQ(projectId, keyFilename);
const bqStub = sandbox.stub(bq, 'bigquery');
但有些方法会一直尝试对谷歌进行实际身份验证,我也需要存根。任何关于如何开始的帮助都会很棒。
【问题讨论】:
标签: node.js unit-testing google-bigquery mocha.js sinon