mercredi 6 avril 2016

TypeError: $.getJSON is not a function mocha test with Frigate

Just started using http://ift.tt/14Ef8tM with a project. Trying to run an example with sinon,chai and mocha.

I don't know why jQuery isn't available in the test suite. I have used it all through my application. When it comes to the testing, it doesn't appear to be available.

example test file:

var assert = require('chai').assert;
var expect = require('chai').expect;
var config = require('../js/config');
var sinon  = require('sinon');
var $      = require('jquery')
var dataService = require('../js/service/map.data');


describe('dataService',function(){
    describe('getMapData',function(){
    var server;
    var response = '{"data":35}';

    before(function () {
        server = sinon.fakeServer.create();
        server.respondWith([200,{"Content-type" : "application/json"}],response);
    });
    after(function () {
      server.restore();
    });
    it('sinon should create a fake server',function () {
        var spy = sinon.spy();
        $.getJSON('/dummy/',spy); //<--- barf!
        server.respond();
        sinon.assert.calledWith(spy,{data:34});
    })
  });
});

Package

Aucun commentaire:

Enregistrer un commentaire