diff --git a/src/auth/spec/AuthManager.spec.ts b/src/auth/spec/AuthManager.spec.ts index b528912..584dc04 100644 --- a/src/auth/spec/AuthManager.spec.ts +++ b/src/auth/spec/AuthManager.spec.ts @@ -57,7 +57,7 @@ describe('AuthManager', () => { expect((authManager as any).logoutUrl).toEqual('/SASLogon/logout?') }) - it('should call the auth callback and return when already logged in', async (done) => { + it('should call the auth callback and return when already logged in', async () => { const authManager = new AuthManager( serverUrl, serverType, @@ -77,10 +77,9 @@ describe('AuthManager', () => { expect(loginResponse.isLoggedIn).toBeTruthy() expect(loginResponse.userName).toEqual(userName) expect(authCallback).toHaveBeenCalledTimes(1) - done() }) - it('should post a login request to the server if not logged in', async (done) => { + it('should post a login request to the server if not logged in', async () => { const authManager = new AuthManager( serverUrl, serverType, @@ -121,10 +120,9 @@ describe('AuthManager', () => { } ) expect(authCallback).toHaveBeenCalledTimes(1) - done() }) - it('should parse and submit the authorisation form when necessary', async (done) => { + it('should parse and submit the authorisation form when necessary', async () => { const authManager = new AuthManager( serverUrl, serverType, @@ -160,10 +158,9 @@ describe('AuthManager', () => { expect(requestClient.authorize).toHaveBeenCalledWith( mockLoginAuthoriseRequiredResponse ) - done() }) - it('should check and return session information if logged in', async (done) => { + it('should check and return session information if logged in', async () => { const authManager = new AuthManager( serverUrl, serverType, @@ -189,7 +186,5 @@ describe('AuthManager', () => { } } ) - - done() }) }) diff --git a/src/test/FileUploader.spec.ts b/src/test/FileUploader.spec.ts index 9e225a2..4b6f678 100644 --- a/src/test/FileUploader.spec.ts +++ b/src/test/FileUploader.spec.ts @@ -1,3 +1,7 @@ +/** + * @jest-environment jsdom + */ + import { FileUploader } from '../FileUploader' import { UploadFile } from '../types' import { RequestClient } from '../request/RequestClient' @@ -35,41 +39,40 @@ describe('FileUploader', () => { new RequestClient('https://sample.server.com') ) - it('should upload successfully', async (done) => { + it('should upload successfully', async () => { const sasJob = 'test/upload' const { files, params } = prepareFilesAndParams() mockedAxios.post.mockImplementation(() => Promise.resolve({ data: sampleResponse }) ) - fileUploader.uploadFile(sasJob, files, params).then((res: any) => { - expect(res).toEqual(JSON.parse(sampleResponse)) - done() - }) + const res = await fileUploader.uploadFile(sasJob, files, params) + + expect(res).toEqual(JSON.parse(sampleResponse)) }) - it('should an error when no files are provided', async (done) => { + it('should an error when no files are provided', async () => { const sasJob = 'test/upload' const files: UploadFile[] = [] const params = { table: 'libtable' } - fileUploader.uploadFile(sasJob, files, params).catch((err: any) => { - expect(err.error.message).toEqual('At least one file must be provided.') - done() - }) + const err = await fileUploader + .uploadFile(sasJob, files, params) + .catch((err: any) => err) + expect(err.error.message).toEqual('At least one file must be provided.') }) - it('should throw an error when no sasJob is provided', async (done) => { + it('should throw an error when no sasJob is provided', async () => { const sasJob = '' const { files, params } = prepareFilesAndParams() - fileUploader.uploadFile(sasJob, files, params).catch((err: any) => { - expect(err.error.message).toEqual('sasJob must be provided.') - done() - }) + const err = await fileUploader + .uploadFile(sasJob, files, params) + .catch((err: any) => err) + expect(err.error.message).toEqual('sasJob must be provided.') }) - it('should throw an error when login is required', async (done) => { + it('should throw an error when login is required', async () => { mockedAxios.post.mockImplementation(() => Promise.resolve({ data: '