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

Running a frisby test from within a promise #127

Closed
dguerrier opened this issue Aug 12, 2014 · 10 comments
Closed

Running a frisby test from within a promise #127

dguerrier opened this issue Aug 12, 2014 · 10 comments

Comments

@dguerrier
Copy link

Is there anyway to get a frisby test to run if it's inside of a promise? I'm using an API based on promises to make API calls to set up the data for tests. If i were to use frisby's http calls it would pollute the test and require a ton of nested callbacks. I would like to simply do something like this.

theAPIcall().then(function(data){
frisby.create('Very useful for HTML, text, or raw output')
.get('http://asciime.heroku.com/generate_ascii?s=Frisby.js')
.inspectBody()
.toss()
});

@tellezhector
Copy link

+1

This will be magnificent. I have to collect a lot of information from an API.
And it is horrible to have nested tests just to do so.

@katerberg
Copy link

This would be very helpful. If I am using an internal promise, then there is no way to have these tests run without this.

@dguerrier
Copy link
Author

I was able to work around this by using Jasmine's beforeEach() and it()
which handle promises

beforeEach(function(done) {

aPromise().then(function(response){
something = response;
}).then(function(){
yourPromise()
done()
})

  }).done

})

});

it("contains spec with an expectation", function() {
frisby.create

})

On Tue, Sep 23, 2014 at 4:50 PM, Diablomarcus notifications@github.com
wrote:

This would be very helpful. If I am using an internal promise, then there
is no way to have these tests run without this.


Reply to this email directly or view it on GitHub
#127 (comment).

@katerberg
Copy link

That definitely works. I would prefer a way to not have to wrap all of my frisby test in external jasmine wrappers, but your solution seems to work.

Thanks @dguerrier

@bgdavidx
Copy link

I've created a fork that allows you to use Promises from within frisby. Check it out at https://github.com/bgdavidx/frisby

The API is the same; however you can use .promisedToss() to return a frisby promise. (Requires bluebird)

@oscartcy
Copy link

+1 for official support

@AndyWendt
Copy link

Here is a work around since it is based off of Jasmine and can use done().

For example:

'use strict';

const frisby = require('frisby');
const api = require('./api-helpers');

// api.before returns a promise and is a local file which returns module exports
// describe() & it() are from Jasmine

describe('Products ', () => {
  it("retrieves the products collection", (done) => {
     api.before('Products', 'getCollection').then((seedData) => {
       frisby.create('Ensure products collection is correct ')
         .addHeaders(seedData.meta.headers)
         .get('http://yoursite.dev/api/products')
         .expectHeader('Content-Type', 'application/json')
         .expectStatus(200)
         .toss();
       done();
     });
  });
});

@vlucas
Copy link
Owner

vlucas commented May 18, 2016

Frisby v2.0 will fix this (see #316) since it uses promises internally. There is even a new API method that you can call to return the internal promise object from fetch called promise().

@geolunalg
Copy link

any update on Frisby v2.0

@vlucas
Copy link
Owner

vlucas commented Jul 26, 2017

Frsiby v2.0 alpha is here and ready to use. It is now in the master branch, and can be installed and used via the instructions in the README.

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

8 participants