Skip to content

Commit

Permalink
adjust tests to use actual Response object instead of object approxim…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
pieh committed Mar 19, 2020
1 parent 0e3d84c commit 6909e24
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/__tests__/transformers/GIPHY.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import {

import { cache, getMarkdownASTForFile, parseASTToMarkdown } from '../helpers';

const { Response } = jest.requireActual('node-fetch');
jest.mock('node-fetch', () => jest.fn());

const mockFetch = ({ height, width }) =>
fetchMock.mockResolvedValue({
json: () => Promise.resolve({ height, width }),
});
fetchMock.mockImplementation(() =>
Promise.resolve(new Response(JSON.stringify({ height, width })))
);

beforeEach(() => {
fetchMock.mockClear();
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/transformers/Instagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import { getHTML, shouldTransform } from '../../transformers/Instagram';

import { cache, getMarkdownASTForFile, parseASTToMarkdown } from '../helpers';

const { Response } = jest.requireActual('node-fetch');
jest.mock('node-fetch', () => jest.fn());

const mockFetch = html =>
fetchMock.mockResolvedValue({ json: () => Promise.resolve({ html }) });
fetchMock.mockImplementation(() =>
Promise.resolve(new Response(JSON.stringify({ html })))
);

beforeEach(() => {
fetchMock.mockClear();
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/transformers/Streamable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import {

import { cache, getMarkdownASTForFile, parseASTToMarkdown } from '../helpers';

const { Response } = jest.requireActual('node-fetch');
jest.mock('node-fetch', () => jest.fn());

const mockFetch = html =>
fetchMock.mockResolvedValue({ json: () => Promise.resolve({ html }) });
fetchMock.mockImplementation(() =>
Promise.resolve(new Response(JSON.stringify({ html })))
);

beforeEach(() => {
fetchMock.mockClear();
Expand Down
13 changes: 7 additions & 6 deletions src/__tests__/transformers/Twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { getHTML, shouldTransform } from '../../transformers/Twitter';

import { cache, getMarkdownASTForFile, parseASTToMarkdown } from '../helpers';

const { Response } = jest.requireActual('node-fetch');
jest.mock('node-fetch', () => jest.fn());

const mockFetch = (status, moment) =>
fetchMock
.mockResolvedValueOnce({ json: () => Promise.resolve({ html: status }) })
.mockResolvedValueOnce({ json: () => Promise.resolve({ html: status }) })
.mockResolvedValueOnce({ json: () => Promise.resolve({ html: moment }) })
.mockResolvedValueOnce({ json: () => Promise.resolve({ html: moment }) })
.mockResolvedValueOnce({ json: () => Promise.resolve({ html: moment }) })
.mockResolvedValueOnce({ json: () => Promise.resolve({ html: moment }) });
.mockResolvedValueOnce(new Response(JSON.stringify({ html: status })))
.mockResolvedValueOnce(new Response(JSON.stringify({ html: status })))
.mockResolvedValueOnce(new Response(JSON.stringify({ html: moment })))
.mockResolvedValueOnce(new Response(JSON.stringify({ html: moment })))
.mockResolvedValueOnce(new Response(JSON.stringify({ html: moment })))
.mockResolvedValueOnce(new Response(JSON.stringify({ html: moment })));

beforeEach(() => {
fetchMock.mockReset();
Expand Down

0 comments on commit 6909e24

Please sign in to comment.