использование переменной server в тестах ember-cli-mirage

Я пытаюсь использовать ember-cli-mirage в своих тестах, но сталкиваюсь с проблемами. Я использую ember и ember-data 2.1.0, так что это может иметь какое-то отношение к этому.

Я могу использовать мираж в разработке просто отлично. Я определил фабрики, маршруты, сценарии и т. д. без проблем.

Проблема в том, что я пытаюсь создать модели в тестах. Тест ниже выдает ошибку:

import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'frontend/tests/helpers/start-app';

let application;

module('Acceptance | Customer', {
  beforeEach() {
    application = startApp();
  },

  afterEach() {
    Ember.run(application, 'destroy');
  }
});

test('viewing customers', function(assert) {
    server.createList('customer', 2);
    visit('/admin/customers');
    andThen(() => assert.equal(find('#customers-table tbody tr').length, 2));
});

Это приводит к:

not ok 1 PhantomJS 1.9 - Acceptance | Customer: viewing customers
    ---
        actual: >
            null
        message: >
            Died on test #1     at http://localhost:7357/assets/test-support.js:3124
                at http://localhost:7357/assets/frontend.js:2434
                at http://localhost:7357/assets/vendor.js:150
                at tryFinally (http://localhost:7357/assets/vendor.js:30)
                at http://localhost:7357/assets/vendor.js:156
                at http://localhost:7357/assets/test-loader.js:29
                at http://localhost:7357/assets/test-loader.js:21
                at http://localhost:7357/assets/test-loader.js:40
                at http://localhost:7357/assets/test-support.js:6846: 'undefined' is not a function (evaluating 'newCollection[method].bind(newCollection)')
        Log: |
    ...

Должен ли я где-то загружать мираж?


person David    schedule 17.10.2015    source источник


Ответы (1)


На самом деле это вызвано тем, что Phantom 1.9 не имеет bind (вы можете видеть в сообщении об ошибке, undefined относится к привязке).

Если вы просматриваете другие примечания раздел документации по установке, вы увидите, что вы можете обойти это, установив ember-cli-es5 -shim (или обновление до PhantomJS 2.0).

person Sam Selikoff    schedule 18.10.2015