Skip to content

Instantly share code, notes, and snippets.

@mordaha
Forked from vovkasm/Chat.spec.tsx
Created June 24, 2019 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mordaha/47655d716c0fcc90e8761cf9c3ef2bfd to your computer and use it in GitHub Desktop.
Save mordaha/47655d716c0fcc90e8761cf9c3ef2bfd to your computer and use it in GitHub Desktop.
Sample test (not full, only to show code)
mport 'jest'
import { clock } from 'testing/setupFakeTimers'
import { TestController as Ctrl } from 'testing/testController'
import React from 'react'
import Renderer, { act } from 'react-test-renderer'
beforeEach(() => {
// simplifyed code
Ctrl.setup()
clock.tick(200)
Ctrl.simulateApplicationStart()
clock.tick(200)
})
afterEach(() => {
// wait application to stop any activity (because LazyLoader can't cancel its promises)
clock.runAll()
Ctrl.reset()
jest.clearAllMocks()
clock.reset()
})
it('renders empty screen until chat will be loaded', () => {
const r = Renderer.create(<ChatScreen screenId="screen0" chatId="ch0" />)
expect(r.toJSON()).toMatchSnapshot()
act(() => {
Ctrl.app.model.chats.addFromApi({
id: 'ch0',
lastSeen: '',
lastSeenMessageId: '',
peerId: 'u1',
type: 'personal',
unreadCount: 0,
})
})
expect(r.toJSON()).toMatchSnapshot()
act(() => {
Ctrl.app.model.users.addFromApi(UserSysType.Short, {
about: '',
age: 30,
authType: ['local'],
avatarUrl: 'https://avatars/u1',
chatAllowed: true,
displayName: 'User 1',
id: 'u1',
sex: 'm',
subscribedCategories: [],
})
})
expect(r.toJSON()).toMatchSnapshot()
r.unmount()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment