Skip to content

Instantly share code, notes, and snippets.

@vovkasm
Created June 18, 2019 07:35
Show Gist options
  • Save vovkasm/9cf8f82330f51e1c28b026815085a1e3 to your computer and use it in GitHub Desktop.
Save vovkasm/9cf8f82330f51e1c28b026815085a1e3 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