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

Assertions within async callbacks timeout instead of failing #78

Open
IstoraMandiri opened this issue Aug 5, 2014 · 4 comments
Open

Comments

@IstoraMandiri
Copy link

So it seems like any assertions that are made within meteor-specifc callbacks (e.g. Meteor.setTimeout or Meteor.call) will not fail the test immediately, and will wait for mocha to timeout.

@dangilkerson has a solution in #70. The solution is illustrated in the last example below, but it would be nice to not have to do this.

Seems like failed assertions should behave in the same way as if the assertion passes, and cause the test to fail immediately. It also means that unless you use the try/catch solution, the test failure is reported as 'timeout' instead of the actual assertion.

Here's a few examples to demonstrate:

      it 'will pass immediately', (done) ->
        Meteor.setTimeout ->
          assert.equal 1, 1
          done()
        , 1

      it 'will fail after 2000ms', (done) ->
        Meteor.setTimeout ->
          assert.equal 1, 2
          done()
        , 1

      it 'will fail immediately', (done) ->
        Meteor.setTimeout ->
          try
            assert.equal 1, 2
            done()
          catch err
            done err
        , 1
@IstoraMandiri
Copy link
Author

Perhaps this is a similar issue?
mochajs/mocha#1128

I have tested and it does seem that wrapping in setTimeout as suggested will 'cure' the problem also.

      it 'will fail immediately v2', (done) ->
        Meteor.setTimeout ->
          setTimeout ->
            assert.equal 1, 2
            done()
          , 0
        , 1

Although unfortunately this seriously messes with the output, even getting rid of the time taken.

will fail immediately - 45 ms output from try/catch method above
Failed: expected 1 to equal 2
AssertionError: expected 1 to equal 2

will fail immediately v2 - ms is missing the time
Failed: Uncaught AssertionError: expected 1 to equal 2 (http://localhost:5000/packages/mocha-web-velocity.js?6ed744554c43b4843d8a3ca38a7eccf7012e64bf:6980)
Error: Uncaught AssertionError: expected 1 to equal 2 (http://localhost:5000/packages/mocha-web-velocity.js?6ed744554c43b4843d8a3ca38a7eccf7012e64bf:6980)
at global.onerror (http://localhost:5000/packages/mocha-web-velocity.js?6ed744554c43b4843d8a3ca38a7eccf7012e64bf:5773:10)

@timstott
Copy link

timstott commented Aug 6, 2014

I'm facing the exact same problem. The try/catch workaround mentioned in #70 works. But as suggested by @hitchcott, it would nice to not have to do this.

@neopostmodern
Copy link

Could this please be marked somewhere in the README?
It's an incredibly unintuitive behavior and coming up with the workaround isn't that obvious either.
Especially for people that are just getting started...

@sferoze
Copy link

sferoze commented Jun 11, 2015

I tried using the try/catch in my Meteor app to catch the asynchronous assertions and it prevented velocity from working. I had to remove the try catch and velocity would then reload and run the tests again.

The solution that worked for me was wrapping the chai.assert statement in a setTimeout. Does this solution work for others using Meteor mocha? Any downsides to this hack/fix?

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

4 participants