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

await not working as advertised #229

Open
budleigh opened this issue Nov 4, 2017 · 2 comments
Open

await not working as advertised #229

budleigh opened this issue Nov 4, 2017 · 2 comments

Comments

@budleigh
Copy link

budleigh commented Nov 4, 2017

Hi there - feel like a bit of an idiot, been staring at this for nearly an hour.

            it('fails', async function () {
                expect(await UserInterface.newUser({
                    email: '[email protected]',
                    password: 'anotherpassword',
                })).to.be.rejectedWith(MongoError);
            });

fails to capture the error:

    .newUser
         when the user already exists
           fails:
     MongoError: E11000 duplicate key error collection: huang_test.users index: email_1 dup key: { : "[email protected]" }
      at Function.MongoError.create (node_modules\mongodb-core\lib\error.js:31:11)
      at toError (node_modules\mongodb\lib\utils.js:139:22)
      at node_modules\mongodb\lib\collection.js:668:23
      at handleCallback (node_modules\mongodb\lib\utils.js:120:56)
      at node_modules\mongodb\lib\bulk\unordered.js:465:9
      at handleCallback (node_modules\mongodb\lib\utils.js:120:56)
      at resultHandler (node_modules\mongodb\lib\bulk\unordered.js:413:5)
      at node_modules\mongodb-core\lib\connection\pool.js:469:18
      at _combinedTickCallback (internal/process/next_tick.js:131:7)
      at process._tickCallback (internal/process/next_tick.js:180:9)

The docs are pretty straightforward here, so I assume it's something I'm doing wrong.

@meeber
Copy link
Contributor

meeber commented Nov 5, 2017

@budleigh I think you just need to pull await out of expect:

await expect(Promise.reject(new TypeError())).to.be.rejectedWith(TypeError);

@leomelzer
Copy link

@meeber Thanks! Just had the same issue. Pulling await out works for me.

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

3 participants