Skip to content

Commit

Permalink
test: ensure our enums are types and values (#3146)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken authored Feb 18, 2022
1 parent 25d22b2 commit b0d4413
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/types/enum.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { expectAssignable, expectType } from 'tsd';

import {
AuthMechanism,
AutoEncryptionLoggerLevel,
BatchType,
BSONType,
Compressor,
CURSOR_FLAGS,
CursorFlag,
ExplainVerbosity,
GSSAPICanonicalizationValue,
LoggerLevel,
ProfilingLevel,
ReadConcernLevel,
ReadPreferenceMode,
ReturnDocument,
ServerApiVersion,
ServerType,
TopologyType
} from '../../src/index';

const num: number = Math.random();

// In our index.ts we clump CURSOR_FLAGS with the enums but its an array
expectType<CursorFlag>(CURSOR_FLAGS[num]);

// Explain is kept as type string so we can automatically allow any new level to be passed through
expectAssignable<string>(Object.values(ExplainVerbosity)[num]);

// Note both the Enum name and a property on the enum are the same type
// Object.values(x)[num] gets a union of the all the value types
expectType<AuthMechanism>(Object.values(AuthMechanism)[num]);
expectType<AutoEncryptionLoggerLevel>(Object.values(AutoEncryptionLoggerLevel)[num]);
expectType<BatchType>(Object.values(BatchType)[num]);
expectType<BSONType>(Object.values(BSONType)[num]);
expectType<Compressor>(Object.values(Compressor)[num]);
expectType<GSSAPICanonicalizationValue>(Object.values(GSSAPICanonicalizationValue)[num]);
expectType<LoggerLevel>(Object.values(LoggerLevel)[num]);
expectType<ProfilingLevel>(Object.values(ProfilingLevel)[num]);
expectType<ReadConcernLevel>(Object.values(ReadConcernLevel)[num]);
expectType<ReadPreferenceMode>(Object.values(ReadPreferenceMode)[num]);
expectType<ReturnDocument>(Object.values(ReturnDocument)[num]);
expectType<ServerApiVersion>(Object.values(ServerApiVersion)[num]);
expectType<ServerType>(Object.values(ServerType)[num]);
expectType<TopologyType>(Object.values(TopologyType)[num]);

0 comments on commit b0d4413

Please sign in to comment.