Fungsi pauseTest() dari ember-qunit tidak berfungsi seperti yang diharapkan dalam tes Integrasi dengan sintaks lama

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}}/>`);
  ...
}

Gagal:

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

Ini berfungsi dengan baik dalam tes Penerimaan, karena:

// ./tests/helpers/start-app.js
export default function startApp(attrs) {
  ...
    application.injectTestHelpers();
  ...
}

Bagaimana cara membuatnya bekerja dalam tes Integrasi?

Catatan: Dalam sintaks modern, ini juga berfungsi dengan baik:

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}}/>`);
  });
}
1
Aleksei Strizhak 19 November 2020, 22:17

1 menjawab

Jawaban Terbaik

Solusi:

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}}/>`);
  ...
}

Sumber: https://github.com/emberjs/ember-mocha/ issue/75#issuecomment-263142520

0
Alexey Strizhak 19 November 2020, 19:17