Sha256: df44b517e78cda85bb234242fe53db5aa4540a02d3f01dba58cdb474fee5fdb6

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

import { compile } from 'ember-template-compiler';
import { ENV } from '@ember/-internals/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

1 entries across 1 versions & 1 rubygems

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