Coder Social home page Coder Social logo

Comments (5)

dareid avatar dareid commented on August 20, 2024

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.

troywoy avatar troywoy commented on August 20, 2024

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.

dareid avatar dareid commented on August 20, 2024

@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.

troywoy avatar troywoy commented on August 20, 2024

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.

dareid avatar dareid commented on August 20, 2024

I will close this issue, hopefully I have solved your issue. If not, please feel free to reopen.

from chakram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.