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

Assertion always pass, no matter promise result #84

Closed
endorama opened this issue Feb 18, 2015 · 3 comments
Closed

Assertion always pass, no matter promise result #84

endorama opened this issue Feb 18, 2015 · 3 comments

Comments

@endorama
Copy link

Hello, thanks for this library!

I'm stuck in trying to make chai-as-promised work. For some reason tests always pass or always fail, regardless promise result.

"promised" code:

function loadFile (filePath) {
    var deferred = Q.defer();
    deferred.reject(new Error('Some error'));
    return deferred.promise;
}

Test code:

it('should permit comments in project file', function() {
    return loadFile(projectFile).should.be.ok;
});

This test always pass, while is obvious that the promise is being rejected. What am I missing?
I read about issue #56 but this doesn't seem the case ( or is it?? ) as I'm rejecting with a proper Error.

If I change the code to use eventually:

it('should permit comments in project file', function() {
    return loadFile(projectFile).should.eventually.be.ok;
});

the test fails, but if I update the code to resolve the promise:

function loadFile (filePath) {
    var deferred = Q.defer();
    deferred.resolve('foobar');
    return deferred.promise;
}

the test now always fails...

Any help is appreciated :)

@domenic
Copy link
Collaborator

domenic commented Feb 18, 2015

return loadFile(projectFile).should.be.ok;

You are not using Chai as Promised here at all. You are using just plain Chai. .should.be.ok tests if the object is truthy. All promises are objects, and so are automatically truthy.

return loadFile(projectFile).should.eventually.be.ok;

this should work. Can you produce a complete example file I can run, unmodified, in Mocha that demonstrates the problem?

@endorama
Copy link
Author

You are not using Chai as Promised here at all. You are using just plain Chai. .should.be.ok tests if the object is truthy. All promises are objects, and so are automatically truthy.

This clarifies a lot the use of eventually ( I misunderstood the Readme ).

Cleaning up my code to create a valid example file I found the error that confused me in the beginning, and was a simple typo ( a P instead of p in one of the test cases, that obviously was always failing :( )

Thanks for the help! Everything is working great now. Closing

@domenic
Copy link
Collaborator

domenic commented Feb 18, 2015

Awesome. If you can think of ways to clarify the readme, feel free to send a pull request.

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

2 participants