Error: 'ReferenceError: pauseTest is not defined' in integration tests with moduleForComponent syntax
Error: 'ReferenceError: pauseTest is not defined' in integration tests with moduleForComponent syntax
ember-qunit 中的 pauseTest()
函数在使用旧语法的集成测试中无法按预期工作
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('my-component, 'Integration | Component | MyComponent', {
integration: true
});
test('it renders', function(assert) {
return pauseTest();
this.render(hbs`{{my-component}}/>`);
...
}
失败:
Died on test #1 at Module.callback (http://localhost:4200/assets/tests.js:118959:24)
at Module.exports (http://localhost:4200/assets/vendor.js:111:32)
at requireModule (http://localhost:4200/assets/vendor.js:32:18)
at EmberExamQUnitTestLoader.<anonymous> (http://localhost:4200/assets/test-support.js:29031:11)
at EmberExamQUnitTestLoader.require (http://localhost:4200/assets/test-support.js:29021:27)
at http://localhost:4200/assets/test-support.js:29545:90
at Array.forEach (<anonymous>): pauseTest is not defined@ 698 ms
Source:
ReferenceError: pauseTest is not defined
at Object.<anonymous> (http://localhost:4200/assets/tests.js:118960:5)
at runTest (http://localhost:4200/assets/test-support.js:20889:30)
at Test.run (http://localhost:4200/assets/test-support.js:20875:6)
at http://localhost:4200/assets/test-support.js:21096:12
at advanceTaskQueue (http://localhost:4200/assets/test-support.js:20488:6)
at Object.advance (http://localhost:4200/assets/test-support.js:20469:4)
at begin (http://localhost:4200/assets/test-support.js:22241:20)
at http://localhost:4200/assets/test-support.js:21483:6
它在验收测试中运行良好,因为:
// ./tests/helpers/start-app.js
export default function startApp(attrs) {
...
application.injectTestHelpers();
...
}
如何让它在集成测试中工作?
注意:
在现代语法中,它也能正常工作:
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
module('Integration | Component | MyComponent', function(hooks) {
test('it renders', async function(assert) {
return this.pauseTest();
await render(hbs`{{my-component}}/>`);
});
}
解决方法:
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import Ember from 'ember';
moduleForComponent('my-component, 'Integration | Component | MyComponent', {
integration: true
});
test('it renders', function(assert) {
return Ember.Test._helpers.pauseTest.method();
this.render(hbs`{{my-component}}/>`);
...
}
来源:https://github.com/emberjs/ember-mocha/issues/75#issuecomment-263142520
ember-qunit 中的 pauseTest()
函数在使用旧语法的集成测试中无法按预期工作
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('my-component, 'Integration | Component | MyComponent', {
integration: true
});
test('it renders', function(assert) {
return pauseTest();
this.render(hbs`{{my-component}}/>`);
...
}
失败:
Died on test #1 at Module.callback (http://localhost:4200/assets/tests.js:118959:24)
at Module.exports (http://localhost:4200/assets/vendor.js:111:32)
at requireModule (http://localhost:4200/assets/vendor.js:32:18)
at EmberExamQUnitTestLoader.<anonymous> (http://localhost:4200/assets/test-support.js:29031:11)
at EmberExamQUnitTestLoader.require (http://localhost:4200/assets/test-support.js:29021:27)
at http://localhost:4200/assets/test-support.js:29545:90
at Array.forEach (<anonymous>): pauseTest is not defined@ 698 ms
Source:
ReferenceError: pauseTest is not defined
at Object.<anonymous> (http://localhost:4200/assets/tests.js:118960:5)
at runTest (http://localhost:4200/assets/test-support.js:20889:30)
at Test.run (http://localhost:4200/assets/test-support.js:20875:6)
at http://localhost:4200/assets/test-support.js:21096:12
at advanceTaskQueue (http://localhost:4200/assets/test-support.js:20488:6)
at Object.advance (http://localhost:4200/assets/test-support.js:20469:4)
at begin (http://localhost:4200/assets/test-support.js:22241:20)
at http://localhost:4200/assets/test-support.js:21483:6
它在验收测试中运行良好,因为:
// ./tests/helpers/start-app.js
export default function startApp(attrs) {
...
application.injectTestHelpers();
...
}
如何让它在集成测试中工作?
注意: 在现代语法中,它也能正常工作:
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
module('Integration | Component | MyComponent', function(hooks) {
test('it renders', async function(assert) {
return this.pauseTest();
await render(hbs`{{my-component}}/>`);
});
}
解决方法:
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import Ember from 'ember';
moduleForComponent('my-component, 'Integration | Component | MyComponent', {
integration: true
});
test('it renders', function(assert) {
return Ember.Test._helpers.pauseTest.method();
this.render(hbs`{{my-component}}/>`);
...
}
来源:https://github.com/emberjs/ember-mocha/issues/75#issuecomment-263142520