我试图在我的测试中使用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: |
...
我应该在某个地方引导海市蜃楼吗?
答案 0 :(得分:5)
这实际上是由Phantom 1.9没有bind
造成的(你可以在错误信息中看到,undefined
指的是绑定)。
如果您查看安装文档的other notes部分,则会看到您可以通过安装ember-cli-es5-shim(或升级到PhantomJS 2.0)来解决此问题。