Comments (5)
Chakram will fail tests, in their afterEach hook, if any of the test's expectations are not fulfilled. Expectations are only fulfilled if the test waits for them, this can be achieved by returning a promise from the 'it' block which fulfills once all the expectations have ran.
In the case above, you are not returning a promise, and hence the test is never actually getting performed. For this reason, the afterEach hook will fail it, which is why you see a success then a failure.
If you change your code to be:
it('should have a 200 response status', function() {
var google = chakram.get("http://google.com");
return expect(google).to.have.status(200);
});
This should pass and fail correctly. There is also the method chakram.wait(), which will return a promise which will wait for all expectations to complete (in the current scope).
In test/base.js there is some tests which may be of interest to you.
If you have any issues I would be happy to help out!
from chakram.
I too am having similar issues. I've tried both suggested examples in this thread, but with no success:
it('should have a 200 response status', function(done) {
var response = chakram.get('http://www.google.com/');
return expect(response).to.have.status(200);
});
it('should have a 200 response status', function(done) {
var response = chakram.get('http://www.google.com/');
expect(response).to.have.status(200);
return chakram.wait();
});
The output is as follows for both tests (my timeout is increased to 5000 for slow VPN connection speeds): Error: timeout of 5000ms exceeded. Ensure the done() callback is being called in this test.
What did work properly for me was the approach in the original comment:
it('should have a 200 response status', function(done) {
var response = chakram.get('http://www.google.com/');
response.then(function(result) {
try {
expect(result).to.have.status(200);
done();
}
catch (e) {
done(e);
}
});
});
Which produced this output: ✓ should have a 200 response status (248ms)
.
Any suggestions as to why my setup fails to run in the manner that the example documentation does would be helpful. I have adjusted mine to match that of the first comment (Mocha 2.2.4, chai 2.3.0, chai-as-promised 5.0.0).
from chakram.
@twh1808 your first two examples include a done parameter on the 'it' block, this can be used to create asynchronous tests. The other method is returning a promise. If you specify a done parameter, the promise is ignored.
If you want to use promises (which your examples are attempting to do), remove the done parameter.
So the following should work:
it('should have a 200 response status', function() {
var response = chakram.get('http://www.google.com/');
return expect(response).to.have.status(200);
});
it('should have a 200 response status', function() {
var response = chakram.get('http://www.google.com/');
expect(response).to.have.status(200);
return chakram.wait();
});
from chakram.
Wow, so simple... I would not have guessed including done
as a parameter would have affected that, but clearly it does. Now all of the example tests in my original comment pass with flying colors.
Thanks!
from chakram.
I will close this issue, hopefully I have solved your issue. If not, please feel free to reopen.
from chakram.
Related Issues (20)
- Jasmine support for chakram HOT 1
- Asserting API with dot (.) on field name
- I want to get status code HOT 1
- Error getting the example to work HOT 1
- Body in request
- Need help on a test for demo HOT 3
- JavaScript heap out of memory
- mocha "before all" hook stopped working HOT 1
- Successful retries don't let test pass
- Not able to pass on the certificates using chakram library.
- Error: self signed certificate
- send sessio id and xsrf token to chakram post api
- No files found
- For chakram.patch(url,data,params), it seems that data is required HOT 1
- 404 Not found stringify-clone@^1.0.0 HOT 1
- rt to es6
- Unable to validate JSON Schema - error: Invalid type: undefined (expected object)
- Handle response as buffer
- Documentation for 'comprise'
- Request to keep this great project active HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chakram.