Skip to content

Commit 9f3b295

Browse files
committed
test(hyper): add missing tests for Hyper class
1 parent ee605df commit 9f3b295

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/hyper.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { enableFetchMocks } from 'jest-fetch-mock';
2+
import { Hyper } from './hyper';
3+
4+
enableFetchMocks();
5+
6+
describe('Hyper class', () => {
7+
afterEach(() => fetchMock.resetMocks());
8+
9+
describe('apiKey property', () => {
10+
it('should throw an error if no API key is provided', () => {
11+
expect(() => new Hyper()).toThrow(
12+
'Missing API key. Pass it to the constructor `new Hyper("hyper_123...")` or set the HYPER_API_KEY environment variable.',
13+
);
14+
15+
expect(() => new Hyper('hyper_1234')).not.toThrow(
16+
'Missing API key. Pass it to the constructor `new Hyper("hyper_123...")` or set the HYPER_API_KEY environment variable.',
17+
);
18+
});
19+
});
20+
21+
describe('fetchRequest method', () => {
22+
it('should return error if response is not ok', async () => {
23+
const hyper = new Hyper('hyper_1234');
24+
25+
fetchMock.mockOnce(JSON.stringify({ error: 'Not found' }), {
26+
status: 404,
27+
});
28+
29+
const result = await hyper['fetchRequest']({ endpoint: '/not-found' });
30+
31+
expect(result).toEqual({ data: null, error: 'Not found' });
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)