Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

afterEach hook is called after the timeout expires when using with chai and chai-as-promised #1421

Closed
rolandjitsu opened this issue Nov 7, 2014 · 1 comment

Comments

@rolandjitsu
Copy link

I've opened up an issue on the Chai As Promised plugin as well since I am uncertain what is happening, but the problem is that the afterEach hook in the test suite gets called after the timeout of 2000 milliseconds, thus my test fails.

"use strict";


describe("Promise", function () {

    var $rootScope,
        $scope,
        $q;

    beforeEach(angular.mock.inject(function (_$rootScope_, _$q_) {
        $rootScope = _$rootScope_;
        $q = _$q_;
        $scope = $rootScope.$new();
    }));

    afterEach(function () {
        $scope.$apply();
    });

    it("should resolve promise and eventually return", function () {

        var defer = $q.defer();

        defer.resolve("incredible, this works like a charm");

        return defer.promise.should.eventually.deep.equal("incredible, this works like a charm");
    });

    it("should resolve promises as expected", function () {

        var fst = $q.defer(),
            promise = fst.promise,
            snd = $q.defer();

        promise
            .then(function (value) {
                value.should.eql("phew, this works");
            });

        fst.resolve("phew, this works");
        snd.resolve("wow, this works as well");

        var all = $q.all([
            promise,
            snd.promise
        ]);

        return all.should.be.fullfiled;
    });

    it("should reject promise because something happens along the way", function () {

        var promise = $q.reject("sadly I failed for some stupid reason");

        promise
            ["catch"](function (reason) {
                reason.should.eql("sadly I failed for some stupid reason");
            });

        var all = $q.all([
            promise
        ]);

        return all.should.be.rejected;
    });

});

Above is just a slim version of what I'm actually running, but the idea is the same and actually the above suite will fail the first and the last test because of a Error: timeout of 2000ms exceeded.

It is a bit strange and I could not figure out what is the cause, the only thing that I discovered as described on the other issue opened on the plugin is that there is some time spent somewhere after the return statement return all.should.be.rejected; and the call of afterEach.

@rolandjitsu
Copy link
Author

The issue is actually not in this lib but in the plugin, thus I will close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant