Closed vveliev closed 8 years ago
You can check each instance's .isRunning();
like this http://jsfiddle.net/45wfgtnd/1
If you can give a example of what your code looks like also.
@SergioCrisostomo , I'am not actually interested in any particular instance .... as from testing stand point, it's not important. What important for a test is to find out if there are any action on the page , pending on request , such that some data may not be present.
Prototype had : Ajax.activeRequestCount
JQuery: jQuery.active
something similar, it may be boolean or number of connections
Should I ask this type of question somewhere else ?! or this is not good reason to add this type of functionality !?
@vveliev This is the good place to ask such questions.
If you have possibility please make a fix suggestion, in a pull request with a update in the docs and some spec.
Cheers
I'm not sure why you'd want this.
Also, you can easily add a RequestFactory
that creates request instances with two subscribed events: request
and complete
, that updates some count, something along the lines of:
var count = 0;
function createRequest(options) {
return new Request(options).addEvents({
request: function() { count++; },
complete: function() { count--; }
});
}
Having the presence of something specific depend on the whether an unspecified request is pending is quite weird from a technical design point of view. Instead, you should probably just listen for the right events to be emitted.
In case you do still want this kind of functionality, you can use the events emitted by the Request instances to create such a state variable.
Consider the following:
var Application = {
running: 0,
request: new Request({
onRequest: function(){
Application.running += 1;
},
onComplete: function(){
Application.running -= 1;
}
})
};
It seems we agree, @arian.
Combine the two answers and you get an application with a request factory:
var Application = {
runningRequests: 0,
createRequest: function(options){
return new Request(options).addEvents({
request: function(){
Application.runningRequests += 1;
},
complete: function(){
Application.runningRequests -= 1;
}
});
})
};
I have no experience with JavaScript or mootools, I'm approaching from test automation side.
So from testing point. I have no knowledge about requests and I cannot come up with the case when I have or need to know actual request.
In single page application, sometimes content of the page changes. And to determine that changes have been rendered. I know 2 solutions: 1.Look for particular element by /id/name/class/text (very specific test's)
2.Have a general check for open connections, and wait for the completion before proceeding.
If this functionality will be useful for development purpose, I will say maybe (as I have no experience in UI development I cannot come up with example. Maybe somebody can back me up on this one.) But it does exist in: Prototype and JQuery, so there should be a reason for it.
you'd change a framework so you can write teardowns in your tests easier?
you can subclass request or modify the prototype in your beforeAll or whatever.
anyway, should move this discussion to support mail list, not GH issues.
On Thursday, 29 October 2015, vveliev notifications@github.com wrote:
I have no experience with JavaScript or mootools, I'm approaching from test automation side.
So from testing point. I have no knowledge about requests and I cannot come up with the case when I have or need to know actual request.
In single page application, sometimes content of the page changes. And to determine that changes have been rendered. I know 2 solutions: 1.Look for particular element by /id/name/class/text (very specific test's)
- Also this does not work for dynamic sections (ex. pagination section, usually elements have same class identification)
2.Have a general check for open connections, and wait for the completion before proceeding.
- From my point this is best solution, for dynamic page sections when element on the page have same identity (class is same) but values are dynamically updated by some trigger.
If this functionality will be useful for development purpose, I will say maybe (as I have no experience in UI development I cannot come up with example. Maybe somebody can back me up on this one.) But it does exist in: Prototype and JQuery, so there should be a reason for it.
— Reply to this email directly or view it on GitHub https://github.com/mootools/mootools-core/issues/2750#issuecomment-152210768 .
Dimitar Christoff
"JavaScript is to JAVA what hamster is to ham" @D_mitar - https://github.com/DimitarChristoff
Thanks to everyone for help!
@DimitarChristoff If everyone who does testing need to add some additional methods around framework. In order to have reliable tests that can be automated. Then you may aswell add this functionality into the framework.
I'm making assumption that there are people who does make test automation.
we all write tests but in all my years of doing js, I've never had to keep count of the number of requests sent by my tests. if you need to know that, stub xhr and set spies that you can assert have been called or calledWith(...args). most of us write unit tests that are decoupled from the responses a server will produce so actual requests out are not desirable.
On Thursday, 29 October 2015, vveliev notifications@github.com wrote:
@DimitarChristoff https://github.com/DimitarChristoff If everyone who does testing need to add some additional methods around framework. In order to have reliable tests that can be automated. Then you may aswell add this functionality into the framework.
I'm making assumption that there are people who does make test automation.
— Reply to this email directly or view it on GitHub https://github.com/mootools/mootools-core/issues/2750#issuecomment-152304487 .
Dimitar Christoff
"JavaScript is to JAVA what hamster is to ham" @D_mitar - https://github.com/DimitarChristoff
Not sure if this is the best place to ask a question / feature request.
As of right now, testing application that is using mootools is not very pleasant task .
Is there a way to some how identify whether there are any active ajax call (true/false or number of active/ pending requests)
If not, is it possible to consider adding this type of functionality to the core. Such that it would be possible to test webapp using more efficient way , without any dependency on particular elements or dummy sleeps of approximated time ....
Thanks!