Skip to content

Commit fb81954

Browse files
committed
✅ Add test for invalid response
1 parent d9e9857 commit fb81954

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/__tests__/diff.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ describe('getDiff', () => {
116116
).rejects.toThrow(`404 - Not Found (${testRemoteSchemaLocation})`);
117117
});
118118

119+
it('throws error on invalid response', () => {
120+
nock(testRemoteSchemaLocation)
121+
.post('', JSON.stringify({ query: introspectionQuery }))
122+
.twice()
123+
.reply(200, { invalid: 'response' });
124+
125+
return expect(
126+
getDiff(testRemoteSchemaLocation, testRemoteSchemaLocation)
127+
).rejects.toThrow(`Invalid response from GraphQL endpoint: ${testRemoteSchemaLocation}`);
128+
});
129+
119130
afterEach(() => {
120131
nock.cleanAll();
121132
});

src/diff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function fetchRemoteSchema(
3737
}
3838

3939
const responseBody = await res.json();
40-
40+
4141
if (!responseBody || !responseBody.data || !responseBody.data.__schema) {
4242
throw new Error(`Invalid response from GraphQL endpoint: ${endpoint}`);
4343
}

0 commit comments

Comments
 (0)