Ember: mock rest spi call using mockjax


#1

I am using ember-cli to develop ember application and ember-data with restful api calls to rails backend.

Also using qunit for testing purpose. (https://github.com/appendto/jquery-mockjax for mocking ajax request)

Here am facing issue while mocking the ajax requests

import Ember from "ember";
import DS from "ember-data";
import { test, moduleFor } from 'ember-qunit';
import startApp from '../../helpers/start-app';
var App;

module('Integration Test', {
  setup: function() {
    App = startApp();
    Ember.$.mockjax({
      url: '/api/v1/offers',
      type: 'GET',
      responseText: {
        offers: [{
          id: 1,
          state: 'draft'
        }]
      }
    });
  },

  teardown: function() {
    Ember.run(App, App.destroy);
  }
});

test('small test', function () {
  console.log("in")
  $.get('/api/v1/offers')
  console.log($.mockjax.mockedAjaxCalls().length);
  console.log("start")

  visit('/offers/1').then(function(){
    equal($('p.item_count').text(), "Offer Items(0)");
  });
  console.log($.mockjax.mockedAjaxCalls().length);
});

On console it produces output as

in
MOCK GET: /api/v1/offers 
Object {url: "/api/v1/offers", type: "get", isLocal: false, global: true, processData: true…}
start
1 
1 

here the api is called using restful adapter, but not using the mocked ajax call.

Can anyone pls help to fix this issue.

Thanks.