-
-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add integration test for subscriptions
- Loading branch information
1 parent
1ddc187
commit 469b0f4
Showing
3 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// @vitest-environment node | ||
import { graphql } from 'msw' | ||
import { setupServer } from 'msw/node' | ||
import { createClient } from 'graphql-ws' | ||
|
||
const server = setupServer() | ||
|
||
beforeAll(() => { | ||
server.listen() | ||
}) | ||
|
||
afterEach(() => { | ||
server.resetHandlers() | ||
}) | ||
|
||
afterAll(() => { | ||
server.close() | ||
}) | ||
|
||
it('intercepts and mocks a GraphQL subscription', async () => { | ||
const api = graphql.link('http://localhost:4000/graphql') | ||
|
||
server.use( | ||
api.pubsub.handler, | ||
api.subscription('OnCommendAdded', () => { | ||
api.pubsub.publish({ | ||
data: { | ||
commentAdded: { | ||
id: '1', | ||
text: 'Hello world', | ||
}, | ||
}, | ||
}) | ||
}), | ||
) | ||
|
||
const client = createClient({ | ||
Check failure on line 37 in test/node/graphql-api/graphql-subscription.test.ts GitHub Actions / buildtest/node/graphql-api/graphql-subscription.test.ts > intercepts and mocks a GraphQL subscription
|
||
url: 'ws://localhost:4000/graphql', | ||
}) | ||
|
||
const subscription = client.iterate({ | ||
query: ` | ||
subscription OnCommendAdded { | ||
commentAdded { | ||
id | ||
text | ||
} | ||
} | ||
`, | ||
}) | ||
|
||
await expect(subscription.next()).resolves.toMatchObject({ | ||
value: { | ||
data: { | ||
commentAdded: { | ||
id: '1', | ||
text: 'Hello world', | ||
}, | ||
}, | ||
}, | ||
}) | ||
}) |