-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as request from '../source/request'; | ||
import wiki from "../source/index"; | ||
import { summaryJson } from './samples'; | ||
const requestMock = jest.spyOn(request, "makeRestRequest"); | ||
|
||
afterAll(() => { | ||
requestMock.mockRestore(); | ||
}) | ||
|
||
test('Throws error if response is error', async () => { | ||
requestMock.mockImplementation(async () => { throw new Error("This is an error") }); | ||
const err = async () => { await wiki.random("some_arg") }; | ||
expect(err).rejects.toThrowError(Error); | ||
}); | ||
|
||
test('Returns summary of random article', async () => { | ||
requestMock.mockImplementation(async () => { return summaryJson }); | ||
const result = await wiki.random("summary"); | ||
expect(result).toStrictEqual(summaryJson); | ||
}); | ||
|
||
test('Request includes arg provided to method', async () => { | ||
requestMock.mockImplementation(async () => { return summaryJson }); | ||
const result = await wiki.random("summary"); | ||
expect(result).toStrictEqual(summaryJson); | ||
expect(requestMock).toBeCalledWith(`page/random/summary`); | ||
}); |