Макет API в модульном тестировании на ядре Nativescript - PullRequest
0 голосов
/ 11 октября 2019

Я реализую модульное тестирование в своем проекте мобильного приложения с ядром nativescript. Я хочу издеваться над API в модульном тестировании, но я не могу это сделать, так что это мой код

// model that I want to test
const myfunction = async (): Promise<myInterface> => {
  const response = await fetch("myURL", {
    method: "GET",
    headers: { "Content-Type": "application/json" }
  });
  const { status, data }: { status: string, data?: any } = await response.json();
  if (!status || status !== "ok") {
    throw new Error("failed fetching from host, status:" + status);
  }

  return data;
}
// my unit testing

import * as dataModel from "../../../shared/models/data";

describe('data', () => {
  describe('myfunction', () => {
    it('get data from api', async () => {
      try {
        // I want to mock api in this place
        const response = await dataModel.myfunction();
      } catch(err) { console.log(err); }
    });
  });
});

Есть ли у него какой-нибудь плагин или что-то, что может издеваться над API из этого мобильного приложенияядро nativescript?

...