Skip to content

Commit

Permalink
refactor(MongoMemoryServer): change "instanceInfo" to be "protected"
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Oct 7, 2020
1 parent d17a47a commit 7390eee
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Expand Up @@ -67,7 +67,7 @@ export interface MongoMemoryServer extends EventEmitter {
}

export class MongoMemoryServer extends EventEmitter {
instanceInfo?: MongoInstanceDataT;
protected instanceInfo?: MongoInstanceDataT;
opts: MongoMemoryServerOptsT;
_state: MongoMemoryServerStateEnum = MongoMemoryServerStateEnum.new;

Expand Down
Expand Up @@ -197,13 +197,9 @@ describe('MongoMemoryServer', () => {

it('should return correct value without "otherDb" being provided', async () => {
const port: number = mongoServer.getPort();
assertion(
mongoServer.instanceInfo,
new Error('"MongoServer.instanceInfo" should be defined!')
);
expect(mongoServer.getUri()).toEqual(
`mongodb://127.0.0.1:${port}/${mongoServer.instanceInfo.dbName}?`
);
const instanceInfo = mongoServer.getInstanceInfo();
assertion(instanceInfo, new Error('"MongoServer.instanceInfo" should be defined!'));
expect(mongoServer.getUri()).toEqual(`mongodb://127.0.0.1:${port}/${instanceInfo.dbName}?`);
});
});

Expand Down
Expand Up @@ -37,6 +37,8 @@ describe('Single mongoServer', () => {
it('should throw error on start if there is already a running instance', async () => {
const mongoServer2 = new MongoMemoryServer();
// this case can normally happen if "start" is called again
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
mongoServer2.instanceInfo = {} as any; // artificially set this to {} to not be undefined anymore
await expect(mongoServer2.start()).rejects.toThrow(
'MongoDB instance already in status startup/running/error. Use debug for more info.'
Expand Down

0 comments on commit 7390eee

Please sign in to comment.