Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: test that cache is required in ssrMode
  • Loading branch information
jackdclark committed Mar 12, 2019
commit af0868d83cbb62834c631e91deb527bb5df2abdb
19 changes: 19 additions & 0 deletions packages/graphql-hooks-ssr/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,23 @@ describe('getInitialState', () => {
expect(result).toEqual({ foo: 'bar' })
expect(resolvedPromises).toBe(2)
})

it("throws if a cache hasn't been provided", async () => {
const MockApp = () => 'hello world'

const mockClient = {
ssrPromises: []
}

expect(
getInitialState({
App: MockApp,
client: mockClient
})
).rejects.toEqual(
new Error(
'A cache implementation must be provided for SSR, please pass one to `GraphQLClient` via `options`.'
)
)
})
})
17 changes: 15 additions & 2 deletions packages/graphql-hooks/test/unit/GraphQLClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ describe('GraphQLClient', () => {
global.fetch = oldFetch
})

it('throws if config.ssrMode is true and no config.cache is provided', () => {
expect(() => {
new GraphQLClient({
...validConfig,
ssrMode: true
})
}).toThrow('GraphQLClient: config.cache is required when in ssrMode')
})

it('assigns config.cache to an instance property', () => {
const cache = { get: 'get', set: 'set' }
const client = new GraphQLClient({ ...validConfig, cache })
Expand All @@ -49,8 +58,12 @@ describe('GraphQLClient', () => {
expect(client.headers).toBe(headers)
})

it('assigns config.ssrMode to an instance property', () => {
const client = new GraphQLClient({ ...validConfig, ssrMode: true })
it('assigns config.ssrMode to an instance property if config.cache is provided', () => {
const client = new GraphQLClient({
...validConfig,
ssrMode: true,
cache: { get: 'get', set: 'set' }
})
expect(client.ssrMode).toBe(true)
})

Expand Down