1

我试图在我的测试中使用 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: |
    ...

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

4

1 回答 1

5

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

如果您查看安装文档的其他注释部分,您会发现可以通过安装ember-cli-es5-shim(或升级到 PhantomJS 2.0)来解决此问题。

于 2015-10-18T18:23:14.070 回答