2015-10-17 43 views
1

我试图在测试中使用ember-cli-mirage,但遇到问题。我使用的是ember和ember-data 2.1.0,因此可能与此有关。在ember-cli-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: | 
    ... 

我应该引导海市蜃楼的地方?

回答

5

这实际上是由Phantom 1.9没有bind引起的(你可以在错误信息中看到,undefined指的是绑定)。

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