Skip to content

Commit

Permalink
fix: new typescript, strict types (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fenster authored May 14, 2020
1 parent 408f113 commit 90034ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
21 changes: 15 additions & 6 deletions test/unit/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('grpc', () => {
'X-Goog-Api-Client': 'gl-node/6.6.0 gccl/0.7.0 gax/0.11.0 grpc/1.1.0',
};
const builder = grpcClient.metadataBuilder(headers);
const abTesting = null;
const abTesting: {} | null = null;
const moreHeaders = {foo: 'bar'};
const metadata = builder(abTesting!, moreHeaders);
assert.deepStrictEqual(metadata.get('foo'), ['bar']);
Expand All @@ -85,7 +85,7 @@ describe('grpc', () => {
'X-Goog-Api-Client': 'gl-node/6.6.0 gccl/0.7.0 gax/0.11.0 grpc/1.1.0',
};
const builder = grpcClient.metadataBuilder(headers);
const abTesting = null;
const abTesting: {} | null = null;
const moreHeaders = {'x-GOOG-api-CLIENT': 'something else'};
const metadata = builder(abTesting!, moreHeaders);
assert.deepStrictEqual(metadata.get('x-goog-api-client'), [
Expand Down Expand Up @@ -117,7 +117,11 @@ describe('grpc', () => {

describe('createStub', () => {
class DummyStub {
constructor(public address: {}, public creds: {}, public options: {}) {}
constructor(
public address: {},
public creds: {},
public options: {[index: string]: string | number | Function}
) {}
}
let grpcClient: GrpcClient;
const dummyChannelCreds = {channelCreds: 'dummyChannelCreds'};
Expand Down Expand Up @@ -195,11 +199,15 @@ describe('grpc', () => {
assert(stub.options.hasOwnProperty(k));
});
// check values
const dummyStub = (stub as unknown) as DummyStub;
assert.strictEqual(
stub.options['grpc.max_send_message_length'],
dummyStub.options['grpc.max_send_message_length'],
10 * 1024 * 1024
);
assert.strictEqual(stub.options['callInvocationTransformer'](), 42);
assert.strictEqual(
(dummyStub.options['callInvocationTransformer'] as Function)(),
42
);
['servicePath', 'port', 'other_dummy_options'].forEach(k => {
assert.strictEqual(stub.options.hasOwnProperty(k), false);
});
Expand Down Expand Up @@ -241,8 +249,9 @@ describe('grpc', () => {
['servicePath', 'port'].forEach(k => {
assert.strictEqual(stub.options.hasOwnProperty(k), false);
});
const dummyStub = (stub as unknown) as DummyStub;
assert.strictEqual(
stub.options['grpc.max_receive_message_length'],
dummyStub.options['grpc.max_receive_message_length'],
10 * 1024 * 1024
);
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/pagedIteration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ describe('paged iteration', () => {
.then(response => {
assert.ok(Array.isArray(response));
assert(Array.isArray(response[0]));
assert.strictEqual(response[0].length, pageSize);
assert.strictEqual((response[0] as Array<{}>).length, pageSize);
for (let i = 0; i < pageSize; ++i) {
assert.strictEqual(response[0][i], expected);
assert.strictEqual((response[0] as Array<{}>)[i], expected);
expected++;
}
done();
Expand Down

0 comments on commit 90034ce

Please sign in to comment.