question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to send multiple requests without nesting?

See original GitHub issue

I would like to send multiple requests sequentially in the beore() method of my test. How do I do this without deeply nesting the code. This is what I have right now:

describe('Conf Test', function() {
    this.timeout(5000);

    before(function(done) {
        sequelize.sync({
            force: true
        }).then(
            function() {
                request(app)
                    .post('/albums')
                    .send({name: 'Beatles'})
                    .set('Accept', 'application/json')
                    .end(function() {
                        request(app)
                            .post('/albums')
                            .send({name: 'Deep Purple'})
                            .set('Accept', 'application/json')
                            .end(function() {
                                done();
                            });
                    });
            }
        );
    });

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
nareshbhatiacommented, Mar 18, 2014

Hi @visionmedia, I was able to use async to remove the deep nesting. My code is definitely more readable now. What do you think of using such utitlities with supertest?

describe('Album Test', function() {
    this.timeout(5000);

    before(function(done) {
        async.series([

            // Sync the database - sequelize.sync()
            function(callback) {
                domain.sequelize.sync({
                    force: true
                }).then(function(/* models */) {
                    callback(null, null);
                });
            },

            // Create an album
            function(callback) {
                request(app)
                    .post('/albums')
                    .send({name: 'Beatles'})
                    .set('Accept', 'application/json')
                    .end(callback);
            },

            // Create another album
            function(callback) {
                request(app)
                    .post('/albums')
                    .send({name: 'Deep Purple'})
                    .set('Accept', 'application/json')
                    .end(callback);
            }
        ], done);
    });
    ...
}
1reaction
ralyodiocommented, Jul 19, 2014

what do you think of supertest-as-promised?

https://github.com/WhoopInc/supertest-as-promised

Is it any good?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send multiple requests without nesting? #108 - GitHub
I would like to send multiple requests sequentially in the beore() method of my test. How do I do this without deeply nesting...
Read more >
Making multiple web api calls synchronously without nesting ...
Suppose you have a function called retrieveProducts , you need to make that function async and then await for the response to keep...
Read more >
How to send multiple requests using axios - Storyblok
Let us start with a small task and sending one request using Axios itself. First, we import axios and define the API/URL we...
Read more >
Using axios.all to make concurrent requests - LogRocket Blog
In this post, we'll learn how to use the axios.all function to make HTTP requests, the difference between using Promise.all and axios ...
Read more >
Handling Nested HTTP Requests Using the Fetch API
First, you will take a look at the naive approach to modeling chained HTTP requests, which is using nested calls to fetch ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found