Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- it('should emit a "data" event when one record is POSTed and parsed', function() {
- let spy = sinon.spy();
- let reader = new Reader(sync_query);
- reader.on('data', spy);
- return chai.request(SYNC_URI)
- .post('/db/_bulk_docs')
- .set("Content-type", "application/json")
- .send({ "docs": [{"user": "tempura"}, {"user": "shrimp"}] })
- .then(function(response){
- expect(response.body).to.have.lengthOf(2);
- sinon.assert.calledOnce(spy);
- // Executes too soon. I can see the event in another listener's logs.
- // I'd like the test to run until the spy fires or a timeout occurs.
- })
- .catch(function(error) {
- throw error;
- });
- // EXITS BEFORE EVENTS are triggered?
- });
- it('should emit a "data" event when one record is POSTed and parsed', function() {
- let reader = new CouchReader(sync_query);
- // This works perfectly to catch when the event is fired but...
- reader.on('data', function(evt) {
- try {
- assert.isOk(evt);
- done();
- } catch (error) {
- done(error);
- }
- });
- chai.request(SYNC_GATEWAY_URI)
- .post('/db/_bulk_docs')
- .set("Content-type", "application/json")
- .send({ "docs": [{"user": "toszter"}, {"user": "bartacus"}] })
- .then(function(response){
- // ...the next expect doesn't get caught when thrown.
- // Can't return chai.request as a promise b/c of the callback.
- expect(response.body).to.have.lengthOf(3);
- })
- .catch(function(error) {
- throw error;
- });
- this.timeout(4000);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement