1.5 KB45 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import {nextTick} from 'shared/testUtils';
9import clientToServerAPI from '../ClientToServerAPI';
10import {resetTestMessages, simulateMessageFromServer} from '../testUtils';
11
12describe('ClientToServer', () => {
13 beforeEach(() => {
14 resetTestMessages();
15 });
16
17 describe('nextMessageMatching', () => {
18 it('resolves when it sees a matching message', async () => {
19 let isResolved = false;
20 const matchingPromise = clientToServerAPI.nextMessageMatching(
21 'uploadFileResult',
22 message => message.id === '1234',
23 );
24
25 matchingPromise.then(() => {
26 isResolved = true;
27 });
28
29 simulateMessageFromServer({type: 'beganLoadingMoreCommits'}); // doesn't match type
30 simulateMessageFromServer({type: 'uploadFileResult', result: {value: 'hi'}, id: '9999'}); // doesn't match predicate
31 await nextTick();
32 expect(isResolved).toEqual(false);
33
34 simulateMessageFromServer({type: 'uploadFileResult', result: {value: 'hi'}, id: '1234'}); // matches
35 expect(matchingPromise).resolves.toEqual({
36 type: 'uploadFileResult',
37 result: {value: 'hi'},
38 id: '1234',
39 });
40
41 simulateMessageFromServer({type: 'uploadFileResult', result: {value: 'hi'}, id: '1234'}); // doesn't crash or anything if another message would match
42 });
43 });
44});
45