Skip to content
New issue

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

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

Already on GitHub? # to your account

Timeout's and other callbacks #200

Closed
Bennit opened this issue Feb 20, 2015 · 3 comments
Closed

Timeout's and other callbacks #200

Bennit opened this issue Feb 20, 2015 · 3 comments

Comments

@Bennit
Copy link

Bennit commented Feb 20, 2015

Is there a way to do a timeout on the client side (or functions that asynchronous, other than the requests built in in frisby) and make sure that the result of expect's that happen inside of the callback get added to the correct test?

var frisby = require('frisby')
frisby.create('Fetch google.com')
    .get('http://google.com')
    .after(function() {
        setTimeout(function() {
            console.log('fetched google.com');
            expect(1).toBe(2);
        },1)
    })
.toss()

This prints out:

Finished in 0.329 seconds
1 test, 0 assertions, 0 failures, 0 skipped


fetched google.com

The scenario I want to test is: I query a REST endpoint and I expect the server behind the REST api to return a response. After returning the response the server does runs followup code (payment) which is supposed to take max X time.

After X time I want to query another REST endpoint and I expect some stuff on the result to show that the system process actually worked.

Kind regards
Ben

@Bennit
Copy link
Author

Bennit commented Feb 20, 2015

The problem is with the time when done is being called:

https://github.com/vlucas/frisby/blob/master/lib/frisby.js#L1149

You execute each callback (which might delay other callbacks) and finally call done().

I'm think promises could provide a clean solution to this problem:

extend's prototype frisby with a function afterP which takes a function that should return a promise.
done() is only called after all the promises returned by afterP callbacks have been resolved or one of them has been rejected.

To keep existing functionality working, the execution of after() also returns a promise that is also added to the Q.all() that waits for all promises to resolve and when resolved, jasmine's done is called.

@tlianza
Copy link

tlianza commented May 14, 2015

Yes... I'm having a tough time structuring some more complex tests due to this structure. Ex. I want to log in, use a response from that login to perform an auth'd operation, use the response from that to call one other api, etc. I haven't found a good way to orchestrate API flows without something like promises.

@vlucas
Copy link
Owner

vlucas commented Jul 26, 2017

This is possible now with Frisby v2 since it does not call any of the Jasmine methods directly. Please check it out and try v2.

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

No branches or pull requests

3 participants