lepffm / issuance

Blogging with Github Issues.
https://github.com/lepffm/issuance/issues
MIT License
1 stars 0 forks source link

[Javascript] frontend api all mocking technique #81

Open lepffm opened 1 year ago

lepffm commented 1 year ago

// 1. make all export service file [ exportAll.js ] export { default as XXService } from 'XXService';

// mocking file [ api-mocks.js j]

import * as _apis from './exportAll.js'
const makeMock = api => {
  Object.getOwnerPropertynames(api).forEach(val => {
    api[val] = jest.fn().mockImplementation((...args) => {
      console.error('${val} ${args}`);
      return Promise.resolve(null):
    }).mockName(val);
  });
};
Object.values(_apis).forEach(api => makeMock(api) );