-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathindex.test.tsx
51 lines (42 loc) · 1.17 KB
/
index.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React from 'react'
import { getInitialState } from './index'
describe('getInitialState', () => {
it('runs all promises and returns state from cache', async () => {
const MockApp = <p>hello world</p>
let resolvedPromises = 0
const promiseCounter = jest.fn().mockImplementation(() => {
resolvedPromises++
return Promise.resolve()
})
const ssrPromises = [promiseCounter(), promiseCounter()]
const mockClient = {
ssrPromises,
cache: {
getInitialState: jest.fn().mockReturnValue({ foo: 'bar' })
}
}
const result = await getInitialState({
App: MockApp,
client: mockClient
})
expect(result).toEqual({ foo: 'bar' })
expect(resolvedPromises).toBe(2)
})
it("throws if a cache hasn't been provided", async () => {
const MockApp = <p>hello world</p>
const mockClient = {
ssrPromises: []
}
expect(
getInitialState({
App: MockApp,
//@ts-ignore
client: mockClient
})
).rejects.toEqual(
new Error(
'A cache implementation must be provided for SSR, please pass one to `GraphQLClient` via `options`.'
)
)
})
})