Skip to content

Instantly share code, notes, and snippets.

@aloverso
Created December 10, 2020 19:01
Show Gist options
  • Select an option

  • Save aloverso/b0541d69f6cabc5d31c5d56ca514a968 to your computer and use it in GitHub Desktop.

Select an option

Save aloverso/b0541d69f6cabc5d31c5d56ca514a968 to your computer and use it in GitHub Desktop.
import externalApiFixtureData from "./onetTestDataTasks.json";
import {getUserDetailsForId} from "./apiClient.ts";
jest.mock("axios");
const mockedAxios = axios as jest.Mocked<typeof axios>;
describe("my cool external API integration", () => {
it("returns description when tasks and related occupations fail", async () => {
mockedAxios.get.mockResolvedValue({data: externalApiFixtureData})
const userDetails = await getUserDetailsForId("172051");
expect(mockedAxios.get).toHaveBeenCalledWith(
"wwww.some-api-url.com/webservices/online/userdetails/172051"
)
expect(userDetails).toEqual({
id: "172051",
name: "Firstname Lastname",
title: "Civil Engineer",
description: "Performs engineering duties in planning and designing building structures",
projects: [
{
id: "1234",
name: "Roadway Design"
},
{
id: "5678",
name: "Airport Structural Maintenance"
}
]
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment