Comments (10)
This has been solved with the new testing API released in v0.14.0
from ember-mocha.
I've been playing around with this some, and have had trouble overriding the existing pauseTest
helper to set the timeout. However, introducing a new helper works.
What I did to override the existing helper was adding this to the test-helper.js
for a demo app:
import { before } from 'mocha';
before(function() {
const originalPauseTestHelper = Ember.Test._helpers.pauseTest.method;
Ember.Test.registerAsyncHelper('pauseTest', () => {
this.timeout(0);
return originalPauseTestHelper();
});
});
My hope was that setting the timeout
in here would override the default value of 2000
and cause the test now to fail. However, this doesn't work; I'm guessing that's the case because the context (this
) of the before
hook needs to be set up before the it
callback is called, but in this case we're setting it after the test has already started.
What did work was setting up a new helper, like this:
import { before } from 'mocha';
before(function() {
const originalPauseTestHelper = Ember.Test._helpers.pauseTest.method;
Ember.Test.registerAsyncHelper('pauseMochaTest', (app, context) => {
context.timeout(0);
return originalPauseTestHelper();
});
});
In this case, the tests passes the context into the helper, like:
pauseMochaTest(this);
So now it can set the timeout correctly, because it's accessing the context of the it
callback instead of the context of the before
.
I've tried to see if there's some way to access the it
context from the before
but it doesn't seem possible. How do you feel about "solving" this with a new helper?
from ember-mocha.
Yeah, we should be able to do that.
from ember-mocha.
On the other hand, it seems like if you return a promise from the it
callback, Mocha just waits for it to resolve. In this cause, pauseTest
returns a promise that doesn't ever resolve, so as long as you do
return pauseTest();
it seems like the test doesn't time out.
from ember-mocha.
I'd be very surprised by that. The default behavior in Mocha is to timeout after 2 sec when either the done
callback is used or a Promise is returned. Not sure if the ember-mocha-adapter mucks around with that though...
from ember-mocha.
@Turbo87 what do you find surprising? I'm happy to throw together a demo repo.
from ember-mocha.
I find it surprising that it doesn't time out when returning a Promise, because that is definitely not the default behavior of Mocha itself.
from ember-mocha.
Hmm, you're right. I guess I was mistaken about what I was seeing earlier when returning pauseTest()
.
from ember-mocha.
this feels silly to have to do this, but I just added a snippet to atom for this and I thought I'd share :)
'timeout then pauseTest()':
'prefix': 'pau',
'body': 'this.timeout(0); return pauseTest();'
from ember-mocha.
I'm updating the docs for this here:
emberjs/ember.js#16740
from ember-mocha.
Related Issues (20)
- Context.owner is undefined (and exceptions are swallowed) HOT 3
- ember-mocha tests failing with Ember 3 HOT 3
- Add `before` and `after` hooks HOT 11
- How to set default timeout HOT 1
- Do I need to install chai? HOT 1
- Mocha does not properly install on fresh Ember 3.6 - Qunit remains and yields TestLoad failure. HOT 1
- TypeError: Cannot read property 'reopen' of undefined HOT 7
- Qunit is not defined errors HOT 11
- Is start() api ready to be released? HOT 4
- start() function isn't in @types/ember-mocha HOT 1
- cannot run tests when building embroider HOT 7
- Catching render error
- Setting same properties name causing tests fail HOT 6
- Does ember-mocha provide blueprints for ember-cli HOT 1
- Error: Please pass the subject owner to beforeEach() HOT 2
- Flaky `Cannot assign to read only property 'owner' of object '#<Context>'` HOT 2
- Upgrade path HOT 7
- Ember Upgrade: global is not defined
- Not compatible with Ember 4+
- #ember-testing-container is alway empty and shows no preview.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-mocha.