-
Notifications
You must be signed in to change notification settings - Fork 349
/
example-test.ts
53 lines (49 loc) · 1.49 KB
/
example-test.ts
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
52
53
import { DashStateClientImpl, GrpcWebError, GrpcWebImpl } from './example';
import { EMPTY } from 'rxjs';
import { NodeHttpTransport } from '@improbable-eng/grpc-web-node-http-transport';
describe('grpc-web', () => {
it('at least compiles', () => {
// TODO move the hand-run `client-ts` integration into here, but for now
// at least check that things compile
const rpc = {
unary: jest.fn(),
invoke: jest.fn(),
};
const client = new DashStateClientImpl(rpc);
client.UserSettings({});
});
it('binds rpc function', () => {
const rpc = {
unary: jest.fn(),
invoke: jest.fn(),
};
const client = new DashStateClientImpl(rpc);
const userSettings = client.UserSettings;
userSettings({});
});
it('throws on client streaming call', () => {
const rpc = {
unary: jest.fn(),
invoke: jest.fn(),
};
const client = new DashStateClientImpl(rpc);
const call = () => client.ChangeUserSettingsStream(EMPTY);
expect(call).toThrowError('ts-proto does not yet support client streaming!');
});
it('throws error of type GrpcWebError', async () => {
const client = new DashStateClientImpl(
new GrpcWebImpl('', {
transport: NodeHttpTransport(),
})
);
try {
await client.UserSettings({});
} catch (e) {
expect(e).toBeInstanceOf(GrpcWebError);
if (e instanceof GrpcWebError) {
expect(e.code).toBeDefined();
expect(e.metadata).toBeDefined();
}
}
});
});