我正在尝试使用 faker-js 包,但我意外地为我的变量
TypeError: Cannot read property 'uuid' of undefined
获得了 businessId
,它尝试使用 faker.datatype.uuid()
通常会在我忘记安装
faker-js
时发生,但这里不是这种情况,我检查是否导入了这个包。因此我对我在这里做错了什么一无所知。
// eslint-disable-next-line import/order
const { initConfig } = require('../../../config');
initConfig();
const sinon = require('sinon');
const faker = require('@faker-js/faker');
const { retryAsyncCall } = require('../../../src/common/helpers/retry-async');
const { createFacebookAdVideoFromUrl } = require('../../../src/common/controllers/facebook/api');
function createPayloadDataBuilder(payload = {}) {
const template = {
accountId: faker.datatype.uuid(),
publicLink: faker.internet.url(),
videoName: faker.lorem.word(),
facebookToken: undefined,
params: null,
businessId: faker.datatype.uuid(),
};
return { ...payload, ...template };
}
describe('Facebook Gateway', () => {
describe('createFacebookAdVideoFromUrl', () => {
describe('Given businessId', () => {
it.only("should create the video calling business's Facebook ids", async () => {
const businessId = faker.datatype.uuid();
console.log(faker, businessId);
const createFacebookAdVideoPayload = createPayloadDataBuilder({
businessId,
});
await createFacebookAdVideoFromUrl(...createFacebookAdVideoPayload);
// sinon.assert.called(retryAsyncCall);
});
});
});
});
找到了!我需要解构导入:
const { faker } = require('@faker-js/faker');