Skip to content

Commit fcb7f10

Browse files
committed
add error test
1 parent 5fa9eec commit fcb7f10

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

src/utils/__tests__/Loqate.test.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Loqate', () => {
4141
expect({ Items }).toEqual(suggestions);
4242
});
4343

44-
it('should throw loqate errors', async () => {
44+
it('should throw errors', async () => {
4545
server.use(errorHandler);
4646

4747
const loqate = Loqate.create('some-key');
@@ -54,10 +54,36 @@ describe('Loqate', () => {
5454
limit: 10,
5555
containerId: 'some-container-id',
5656
});
57-
}).rejects.toThrowError(
58-
new Error(
59-
'Loqate error: {"Error":"2","Description":"Unknown key","Cause":"The key you are using to access the service was not found.","Resolution":"Please check that the key is correct. It should be in the form AA11-AA11-AA11-AA11."}'
60-
)
57+
}).rejects.toThrowError(new Error('Unknown key'));
58+
});
59+
60+
it('should throw loqate errors', async () => {
61+
server.use(errorHandler);
62+
63+
const loqate = Loqate.create('some-key');
64+
65+
let error;
66+
try {
67+
await loqate.find({
68+
text: 'some-text',
69+
language: 'some-language',
70+
countries: ['GB', 'US'],
71+
limit: 10,
72+
containerId: 'some-container-id',
73+
});
74+
} catch (e) {
75+
error = e;
76+
}
77+
78+
expect(error).toEqual(new Error('Unknown key'));
79+
expect(JSON.stringify(error)).toEqual(
80+
JSON.stringify({
81+
Cause: 'The key you are using to access the service was not found.',
82+
Description: 'Unknown key',
83+
Error: '2',
84+
Resolution:
85+
'Please check that the key is correct. It should be in the form AA11-AA11-AA11-AA11.',
86+
})
6187
);
6288
});
6389
});

0 commit comments

Comments
 (0)