Google Cloud Datastore jest nodejs node_modules

我试图通过模拟runQuery和createQuery函数来unit testing下面的listEntities函数。 也许我应该放弃,并使用模拟器进行集成testing。 无论如何,这是我的代码

执行:

const Datastore = require('@google-cloud/datastore'); const datastore = Datastore(); const runQueryDS = query => (datastore.runQuery(query)); const createQueryDS = kind => (datastore.createQuery(kind)); export const listEntities = (kind, runQuery = runQueryDS, createQuery = createQueryDS) => { console.log('listEntities'); const query = createQuery(kind); runQuery(query) .then(results => (results[0])); }; 

testing:

 import { listEntities } from './datastore.api'; describe('datastore api', () => { describe('listEntities', () => { test('should return list of items', () => { console.log('begin test'); const kind = 'TestRun'; const createdQuery = 'createdQuery'; const expectedResult = ['returnedFromQuery']; const returnedFromExecutedQuery = [expectedResult]; const createQuery = jest.fn().mockImplementation(() => (createdQuery)); const runQuery = jest.fn().mockImplementation(() => (returnedFromExecutedQuery)); const result = listEntities(kind, runQuery, createQuery); expect(result).toEqual(expectedResult); }); }); }); 

这是我得到的错误

  FAIL app/datastore.api.test.js ● Test suite failed to run Cannot find module './datastore_client_config' from 'datastore_client.js' at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:191:17) at Object.<anonymous> (node_modules/@google-cloud/datastore/src/v1/datastore_client.js:30:18) 

谢谢!

Interesting Posts