From aeb723d0db8920340b26f70bf1bd1934de710baf Mon Sep 17 00:00:00 2001 From: alxndrsn Date: Fri, 12 Apr 2024 10:06:19 +0000 Subject: [PATCH] Fix --- tests/integration/test.basics.js | 40 +++++++------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/tests/integration/test.basics.js b/tests/integration/test.basics.js index 63dafaf846..3f3f4996b7 100644 --- a/tests/integration/test.basics.js +++ b/tests/integration/test.basics.js @@ -747,8 +747,8 @@ adapters.forEach(function (adapter) { }); [ - null, undefined, + null, [], [{ _id: 'foo' }, { _id: 'bar' }], 'this is not an object', @@ -758,14 +758,10 @@ adapters.forEach(function (adapter) { describe(`Should error when document is not an object #${idx}`, () => { let db; - beforeEach(() => { - db = new PouchDB(dbs.name); - }); - - it('should error for .post()', async () => { + const expectNotAnObject = fn => async () => { let threw; try { - await db.post(badDoc); + await fn(); } catch (err) { threw = true; err.message.should.equal('Document must be a JSON object'); @@ -773,33 +769,15 @@ adapters.forEach(function (adapter) { if (!threw) { throw new Error('should have thrown'); } - }); + }; - it('should error for .put()', async () => { - let threw; - try { - await db.post(badDoc); - } catch (err) { - threw = true; - err.message.should.equal('Document must be a JSON object'); - } - if (!threw) { - throw new Error('should have thrown'); - } + beforeEach(() => { + db = new PouchDB(dbs.name); }); - it('should error for .bulkDocs()', async () => { - let threw; - try { - await db.bulkDocs({docs: [badDoc]}); - } catch (err) { - threw = true; - err.message.should.equal('Document must be a JSON object'); - } - if (!threw) { - throw new Error('should have thrown'); - } - }); + it('should error for .post()', expectNotAnObject(() => db.post(badDoc))); + it('should error for .put()', expectNotAnObject(() => db.put(badDoc))); + it('should error for .bulkDocs()', expectNotAnObject(() => db.bulkDocs({docs: [badDoc]}))); }); });