File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments