From b320a97f7573f055d046a74c69a0b1216f5af5d3 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Wed, 2 Nov 2022 16:31:46 -0500 Subject: [PATCH] test: reorganize tests so they don't leak console warnings --- __tests__/index.test.ts | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index c6ac6fd32..c2ce54132 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -92,24 +92,9 @@ describe('cli', () => { await expect(cli([])).resolves.toContain('OpenAPI / Swagger'); }); - it('should add stored apiKey to opts', async () => { - expect.assertions(1); - const key = '123456'; - const version = '1.0.0'; - conf.set('apiKey', key); - - const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version }); - - await expect(cli(['docs', `--version=${version}`])).rejects.toStrictEqual( - new Error('No path provided. Usage `rdme docs [options]`.') - ); - - conf.clear(); - versionMock.done(); - }); - - describe('logged-in user notifications', () => { + describe('stored API key', () => { let consoleInfoSpy; + const key = '123456'; const getCommandOutput = () => { return [consoleInfoSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n'); }; @@ -117,7 +102,7 @@ describe('cli', () => { beforeEach(() => { conf.set('email', 'owlbert@readme.io'); conf.set('project', 'owlbert'); - conf.set('apiKey', '123456'); + conf.set('apiKey', key); consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(); }); @@ -126,6 +111,23 @@ describe('cli', () => { conf.clear(); }); + it('should add stored apiKey to opts', async () => { + expect.assertions(1); + const version = '1.0.0'; + + const versionMock = getAPIMock() + .get(`/api/v1/version/${version}`) + .basicAuth({ user: key }) + .reply(200, { version }); + + await expect(cli(['docs', `--version=${version}`])).rejects.toStrictEqual( + new Error('No path provided. Usage `rdme docs [options]`.') + ); + + conf.clear(); + versionMock.done(); + }); + it('should inform a logged in user which project is being updated', async () => { await expect(cli(['openapi', '--create', '--update'])).rejects.toThrow( 'The `--create` and `--update` options cannot be used simultaneously. Please use one or the other!'