Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. it('should emit a "data" event when one record is POSTed and parsed', function() {
  2. let spy = sinon.spy();
  3. let reader = new Reader(sync_query);
  4. reader.on('data', spy);
  5. return chai.request(SYNC_URI)
  6. .post('/db/_bulk_docs')
  7. .set("Content-type", "application/json")
  8. .send({ "docs": [{"user": "tempura"}, {"user": "shrimp"}] })
  9. .then(function(response){
  10. expect(response.body).to.have.lengthOf(2);
  11. sinon.assert.calledOnce(spy);
  12. // Executes too soon. I can see the event in another listener's logs.
  13. // I'd like the test to run until the spy fires or a timeout occurs.
  14. })
  15. .catch(function(error) {
  16. throw error;
  17. });
  18. // EXITS BEFORE EVENTS are triggered?
  19. });
  20.  
  21. it('should emit a "data" event when one record is POSTed and parsed', function() {
  22. let reader = new CouchReader(sync_query);
  23. // This works perfectly to catch when the event is fired but...
  24. reader.on('data', function(evt) {
  25. try {
  26. assert.isOk(evt);
  27. done();
  28. } catch (error) {
  29. done(error);
  30. }
  31. });
  32. chai.request(SYNC_GATEWAY_URI)
  33. .post('/db/_bulk_docs')
  34. .set("Content-type", "application/json")
  35. .send({ "docs": [{"user": "toszter"}, {"user": "bartacus"}] })
  36. .then(function(response){
  37. // ...the next expect doesn't get caught when thrown.
  38. // Can't return chai.request as a promise b/c of the callback.
  39. expect(response.body).to.have.lengthOf(3);
  40. })
  41. .catch(function(error) {
  42. throw error;
  43. });
  44. this.timeout(4000);
  45. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement