在 ember-cli-mirage 测试中使用服务器变量

using the server variable in ember-cli-mirage tests

我正在尝试在我的测试中使用 ember-cli-mirage,但 运行 遇到了问题。我正在使用 ember 和 ember-data 2.1.0,所以这可能与此有关。

我可以在开发中很好地使用 Mirage。我已经毫无问题地定义了工厂、路线、场景等。

问题出在我尝试在测试中创建模型时。下面的测试出错了:

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: |
    ...

我应该在某个地方引导海市蜃楼吗?

其实是Phantom 1.9没有bind造成的(可以在报错信息中看到,undefined指的是bind)

如果您查看 other notes section of the Installation docs you'll see you can get around this by installing ember-cli-es5-shim(或升级到 PhantomJS 2.0)。