-
-
Save mordaha/47655d716c0fcc90e8761cf9c3ef2bfd to your computer and use it in GitHub Desktop.
Sample test (not full, only to show code)
This file contains hidden or 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
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