Add test for inferTitle

This commit is contained in:
Goh Jia Hao 2018-06-10 10:47:17 -07:00
parent 04e2f64ba7
commit 49272d1a89
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import axios from 'axios';
import inferTitle from './inferTitle';
jest.mock('axios', () =>
jest.fn(() =>
Promise.resolve({
data: `
<HTML>
<head>
<title>TEST_TITLE</title>
</head>
</HTML>`,
}),
),
);
test('it returns the correct title', async () => {
const result = await inferTitle('someurl');
expect(axios).toHaveBeenCalledTimes(1);
expect(result).toBe('TEST_TITLE');
});