mercredi 16 novembre 2016

PretenderJS throws InvalidBodyException error in EmberJS acceptance test

In my EmberJS 2.9.0 test, I'm using PretenderJS and defining the following:

import Ember from 'ember';
import { test } from 'qunit';
import moduleForAcceptance from 'alnahtha-fe/tests/helpers/module-for-acceptance';
import startApp from '../helpers/start-app';
import Pretender from 'pretender';
import { makesRoute } from '../helpers/pretender/maps/makes-route';

var App;
var p = new Pretender();

moduleForAcceptance('Acceptance | search', {
    beforeEach: function() {
        App = startApp();
        p.map(makesRoute);
        p.map(function() {
            this.get('/api/v1/vehicles', function(/*request*/) {
                var resp =  [
                    {type: "vehicle", id: 1, attributes: {name: "vehicle 1"}},
                    {type: "vehicle", id: 2, attributes: {name: "vehicle 2"}},
                    {type: "vehicle", id: 3, attributes: {name: "vehicle 3"}}
                ];
                console.log(resp);
                return [200, {"content-type": "application/json"}, JSON.stringify({data: resp})];
            });
        });
    },
    afterEach: function() {
        Ember.run(App, 'destroy');
        p.shutdown();
    }
});

test('visiting /search does not require authentication', function(assert) {
  visit('/search');

  andThen(function() {
    assert.equal(currentURL(), '/search');
  });
});

test('visiting /search kicks off ember-infinity model and sends a query', function(assert) {
    visit('/search');

    andThen(() => assert.equal(find('.vehicle-post').length, 1, 'should find at least one vehicle post') );
});

I'm getting the following error when running the tests, which I've exhausted all my thoughts over how to fix:

InvalidBodyException: Attempted to respond to fake XMLHttpRequest with [object Object], which is not a string. at http://localhost:7357/assets/vendor.js, line 67289\n

Would appreciate if someone can provide hints on how this can be fixed, please.

Aucun commentaire:

Enregistrer un commentaire