diff --git a/test/private-api/media.e2e-spec.ts b/test/private-api/media.e2e-spec.ts index 5920ab3e5..7270661aa 100644 --- a/test/private-api/media.e2e-spec.ts +++ b/test/private-api/media.e2e-spec.ts @@ -99,13 +99,16 @@ describe('Media', () => { await fs.unlink(join(uploadPath, fileName)); }); describe('fails:', () => { + beforeEach(async () => { + await fs.rmdir(uploadPath, { recursive: true }); + }); it('MIME type not supported', async () => { await request(app.getHttpServer()) .post('/media') .attach('file', 'test/private-api/fixtures/test.zip') .set('HedgeDoc-Note', 'test_upload_media') .expect(400); - expect(await fs.access(uploadPath)).toBeFalsy(); + await expect(fs.access(uploadPath)).rejects.toBeDefined(); }); it('note does not exist', async () => { await request(app.getHttpServer()) @@ -113,10 +116,9 @@ describe('Media', () => { .attach('file', 'test/private-api/fixtures/test.zip') .set('HedgeDoc-Note', 'i_dont_exist') .expect(400); - expect(await fs.access(uploadPath)).toBeFalsy(); + await expect(fs.access(uploadPath)).rejects.toBeDefined(); }); it('mediaBackend error', async () => { - await fs.rmdir(uploadPath); await fs.mkdir(uploadPath, { mode: '444', }); @@ -126,7 +128,9 @@ describe('Media', () => { .set('HedgeDoc-Note', 'test_upload_media') .expect('Content-Type', /json/) .expect(500); - await fs.rmdir(uploadPath); + }); + afterEach(async () => { + await fs.rmdir(uploadPath, { recursive: true }); }); }); }); diff --git a/test/public-api/media.e2e-spec.ts b/test/public-api/media.e2e-spec.ts index 78a95b56f..d8c3f3b63 100644 --- a/test/public-api/media.e2e-spec.ts +++ b/test/public-api/media.e2e-spec.ts @@ -95,13 +95,16 @@ describe('Media', () => { await fs.unlink(join(uploadPath, fileName)); }); describe('fails:', () => { + beforeEach(async () => { + await fs.rmdir(uploadPath, { recursive: true }); + }); it('MIME type not supported', async () => { await request(app.getHttpServer()) .post('/media') .attach('file', 'test/public-api/fixtures/test.zip') .set('HedgeDoc-Note', 'test_upload_media') .expect(400); - expect(await fs.access(uploadPath)).toBeFalsy(); + await expect(fs.access(uploadPath)).rejects.toBeDefined(); }); it('note does not exist', async () => { await request(app.getHttpServer()) @@ -109,10 +112,9 @@ describe('Media', () => { .attach('file', 'test/public-api/fixtures/test.zip') .set('HedgeDoc-Note', 'i_dont_exist') .expect(400); - expect(await fs.access(uploadPath)).toBeFalsy(); + await expect(fs.access(uploadPath)).rejects.toBeDefined(); }); it('mediaBackend error', async () => { - await fs.rmdir(uploadPath); await fs.mkdir(uploadPath, { mode: '444', }); @@ -122,7 +124,9 @@ describe('Media', () => { .set('HedgeDoc-Note', 'test_upload_media') .expect('Content-Type', /json/) .expect(500); - await fs.rmdir(uploadPath); + }); + afterEach(async () => { + await fs.rmdir(uploadPath, { recursive: true }); }); }); });