Skip to content

Commit

Permalink
refactor(MongoMemoryReplSet): change if-error to "assertion"
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Oct 12, 2020
1 parent 8e6e312 commit 179bdbb
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,9 @@ export class MongoMemoryReplSet extends EventEmitter {
* @throws if package "mongodb" is not installed
*/
protected async _initReplSet(): Promise<void> {
if (this._state !== MongoMemoryReplSetStateEnum.init) {
throw new Error('Not in init phase.');
}
log('Initializing replica set.');
if (this.servers.length <= 0) {
throw new Error('One or more servers are required.');
}
log('_initReplSet');
assertion(this._state === MongoMemoryReplSetStateEnum.init, new Error('Not in init phase.'));
assertion(this.servers.length > 0, new Error('One or more servers are required.'));
const uris = this.servers.map((server) => server.getUri());

const con: MongoClient = await MongoClient.connect(uris[0], {
Expand Down

0 comments on commit 179bdbb

Please sign in to comment.