Closed amitguptagwl closed 6 years ago
Try to move router.lookup(request,response);
below the response.on
- event might be fired before you assign an event handler
Thanks. I've changed the code to following
it('should call post handler after main handler', done => {
var request = httpMocks.createRequest({
method: 'POST',
url: '/without/pre/handlers'
});
var response = httpMocks.createResponse({
eventEmitter: require('events').EventEmitter
});
response.on('end', function() {
expect(response._getData()).toEqual(" main -> post.");
expect(response.statusCode ).toEqual(200);
expect(response._isEndCalled()).toBe(true);
done();
});
router.lookup(request,response);
});
Now it is calling response 'end' event. But it's not calling request's 'data' or 'end' event
Are you sure request object has those events? I've checked here https://nodejs.org/docs/latest-v8.x/api/http.html#http_class_http_clientrequest and can't see that request has 'data' or 'end' events
Yes. if I run the server and hit the URL directly. I get the expected response. Which means all the events are being registered successfully at least in the case of direct hit.
In above example, I've also tried with 'body' property. However it is not necessary. Is there anything else I'm missing in above example that I should do?
In addition, I'm using node v9.5.0, and npm v5.6.0. I'm using find-my-way
as router
Could you give an example of your code with subscribing for 'data' or 'end' request events
Here is the link : https://github.com/muneem4node/muneem/blob/master/src/routesMapper.js
Since it is big, it may eat your valuable time.
Is there any luck?
I've recently created a new router अनुमार्गक (anumargak) but it didn't with that as well. Everything is fine when I run the server and hit the URL.
I've just noticed that it doesn't matter which router I'm using, it doesn't call any event on request body.
function fakeRouter(req,res){
req.on("data", chunk => {
console.log(chunk);
});
res.end("kill me");
}
So in above code, it doesn't prints chunk. I tried to call request.write()
but that seems invalid.
I got a partial solution. I need to emit the event myself after calling the lookup or method.
req.emit('data', 'Hello data!');
req.emit('end');
I was expecting it to be the part of the code.
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL