David
David

Reputation: 10738

using the server variable in ember-cli-mirage tests

I'm trying to use ember-cli-mirage in my tests but running into problems. I'm using ember and ember-data 2.1.0 so that may have something to do with this.

I'm able to use mirage in development just fine. I've defined factories, routes, scenarios, etc with no problem.

The problem is when i attempt to create models in tests. The test below errors out:

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));
});

This results in:

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

Should I be bootstrapping mirage somewhere?

Upvotes: 1

Views: 870

Answers (1)

Sam Selikoff
Sam Selikoff

Reputation: 12694

This is actually caused by Phantom 1.9 not having bind (you can see in the error message, undefined refers to bind).

If you view the other notes section of the Installation docs you'll see you can get around this by installing ember-cli-es5-shim (or upgrading to PhantomJS 2.0).

Upvotes: 5

Related Questions