garrensmith commented on a change in pull request #113: Prevent callback users 
seeing Promise rejections
URL: https://github.com/apache/couchdb-nano/pull/113#discussion_r209918212
 
 

 ##########
 File path: tests/integration/attachment/get.js
 ##########
 @@ -18,45 +18,28 @@ const it = harness.it;
 const db = harness.locals.db;
 
 it('should be able to fetch an attachment', function(assert) {
-  db.attachment.insert('new_string', 'att', 'Hello', 'text/plain',
-  function(error, hello) {
-    assert.equal(error, null, 'should store `hello`');
+  let p = db.attachment.insert('new_string', 'att', 'Hello', 'text/plain');
+  assert.ok(helpers.isPromise(p), 'returns Promise');
+  p.then(function(hello) {
     assert.equal(hello.ok, true, 'response ok');
     assert.ok(hello.rev, 'should have a revision number');
-    const p = db.attachment.get('new_string', 'att',
-    function(error, helloWorld) {
-      assert.equal(error, null, 'should get `hello`');
-      assert.equal('Hello', helloWorld.toString(), 'string is reflexive');
-    });
-    assert.ok(helpers.isPromise(p), 'returns Promise');
-    p.then(function(s) {
-      assert.ok(true, 'Promise is resolved');
-      assert.equal('Hello', s.toString(), 'string is reflexive');
-      assert.end();
-    }).catch(function() {
-      assert.ok(false, 'Promise is rejected');
-    });
+    return db.attachment.get('new_string', 'att')
+  }).then(function(helloWorld) {
+    assert.equal('Hello', helloWorld.toString(), 'string is reflexive');
+    assert.end();
   });
 });
 
 it('should insert and fetch a binary file', function(assert) {
-  db.attachment.insert('new_binary', 'att', new Buffer('123'),
-  'text/plain', function(error, hello) {
-    assert.equal(error, null, 'should store `123`');
+  let p = db.attachment.insert('new_binary', 'att', new Buffer('123'), 
'text/plain')
 
 Review comment:
   I think we could create a nice starter issue for anyone interested in 
contributing to clean up the tests to use more modern js functionality

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to