I am trying to use squirejs in a sample test but its not working. I have a couple of modules
Person.js
define(['scripts/boat','scripts/chicken'], function (myBoat,chook) {
var name, age;
var api = {};
api.setName = function (names) {
name = names;
};
api.getName = function () {
return name;
};
api.getBoatSpeed = function() {
myBoat.setDriver(3);
return myBoat.maximumSpeed();
};
api.getMarshal = function() {
return chook.getFeathers();
};
return api;
});
Chicken.js
define(
[], function () {
return {
getFeathers : function () {
console.log('getFeathers called from actual module');
return 100;
}
};
});
In my test i am running a beforeEach
beforeEach(function(done) {
injector = new Squire();
injector.mock("scripts/chicken", mockFeatherService)
.require(['scripts/person'], function (component) {
myChicken = component;
});
done();
});
and my mockfeatherservice looks like
var mockFeatherService = {
getFeathers : function () {
console.log('getFeathers called from MOCK module');
return 1;
}
};
test which fails as it always returns 100 rather than the mocked 1.
it('Its a chicken test', function() {
expect(pers.getMarshal()).to.equal(1);
my issue is that the actual method 'getFeathers' seems to be called from the actual module rather than the mock created in the test - what am i doing wrong?
Test output :
29 08 2015 23:54:58.197:INFO [watcher]: Changed file "/Users/russellholmes/Desktop/require/test/test.js".
LOG: 'getFeathers called from actual module'
LOG: 100
LOG: 'getFeathers called from actual module'
Chrome 44.0.2403 (Mac OS X 10.10.3) When a person Its a chicken test FAILED
AssertionError: expected 100 to equal 1
Aucun commentaire:
Enregistrer un commentaire