Sha256: 6486a77cc1db3d38e6b2a996154b662c2971fdbd6a7555b0c62701ab1b018e79

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

import { compile } from 'ember-template-compiler';
import { ENV } from 'ember-environment';
import AbstractTestCase from './abstract';
import { runDestroy } from '../run';

export default class AbstractApplicationTestCase extends AbstractTestCase {
  _ensureInstance(bootOptions) {
    if (this._applicationInstancePromise) {
      return this._applicationInstancePromise;
    }

    return (this._applicationInstancePromise = this.runTask(() => this.application.boot()).then(
      app => {
        this.applicationInstance = app.buildInstance();

        return this.applicationInstance.boot(bootOptions);
      }
    ));
  }

  visit(url, options) {
    // TODO: THIS IS HORRIBLE
    // the promise returned by `ApplicationInstance.protoype.visit` does **not**
    // currently guarantee rendering is completed
    return this.runTask(() => {
      return this._ensureInstance(options).then(instance => instance.visit(url));
    });
  }

  get element() {
    if (this._element) {
      return this._element;
    } else if (ENV._APPLICATION_TEMPLATE_WRAPPER) {
      return (this._element = document.querySelector('#qunit-fixture > div.ember-view'));
    } else {
      return (this._element = document.querySelector('#qunit-fixture'));
    }
  }

  set element(element) {
    this._element = element;
  }

  afterEach() {
    runDestroy(this.applicationInstance);
    runDestroy(this.application);

    super.teardown();
  }

  get applicationOptions() {
    return {
      rootElement: '#qunit-fixture',
    };
  }

  get routerOptions() {
    return {
      location: 'none',
    };
  }

  get router() {
    return this.application.resolveRegistration('router:main');
  }

  compile(/* string, options */) {
    return compile(...arguments);
  }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
discourse-ember-source-3.5.1.1 dist/es/internal-test-helpers/lib/test-cases/abstract-application.js
discourse-ember-source-3.5.1.0 dist/dist/es/internal-test-helpers/lib/test-cases/abstract-application.js