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

How does Chai-HTTP integrate with Sinon in this situation? #114

Open
MinhLu12 opened this issue Oct 24, 2017 · 0 comments
Open

How does Chai-HTTP integrate with Sinon in this situation? #114

MinhLu12 opened this issue Oct 24, 2017 · 0 comments

Comments

@MinhLu12
Copy link

Here is the route I want to test:

app.post('/api/user', (req, res) => {

        dbService.replaceUserOnDuplicate(req.body, function returnResponse(insertedId) {
            if (insertedId === 0 || insertedId === req.body.id) {
                return res.sendStatus(200);                            
            }
            // TODO_MINH: Send an appropriate error to handle by the front-end
            return res.send({});
        });
    });

I can use chai-http to do something like this (psuedo-code):

it('test', function (done) {
            chai.request(server)
                .post('/api/user')
                .send({ user: SomeUserObject })
                .end(function (err, res) {
                    res.should.have.status(200);
                    done();
                });

        });

However, the api/users route makes a Database call. How would I use sinon to stub this method (replaceUserOnDuplicate) so that it returns a dummy response (like 0, or anything)?

Is it possible? I'm looking at the Chai-HTTP syntax and I see no room to insert any Sinon stubbed methods.

Thanks for your help!

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