Remove references to $rootScope.Shared & .Content in non-view code.

Instead, have them request services that return them so tests don’t need to prepare special state.
This commit is contained in:
Andrew Bloomgarden
2014-01-12 15:05:15 -08:00
parent 77801e458e
commit dc368bb652
14 changed files with 65 additions and 58 deletions

View File

@@ -4,20 +4,19 @@ describe('Inventory Controller', function() {
var scope, ctrl, user, $rootScope;
beforeEach(module('habitrpg'));
beforeEach(inject(function($rootScope, $controller){
beforeEach(inject(function($rootScope, $controller, Shared){
user = {
balance: 4,
stats: {gp: 0},
items: {eggs: {Cactus: 1}, hatchingPotions: {Base: 1}, food: {Meat: 1}, pets: {}},
};
window.habitrpgShared.wrap(user);
Shared.wrap(user);
var mockWindow = {
confirm: function(msg){
return true;
}
};
scope = $rootScope.$new();
$rootScope.Content = window.habitrpgShared.content;
ctrl = $controller('InventoryCtrl', {$scope: scope, User: {user: user}, $window: mockWindow});
}));
@@ -74,9 +73,9 @@ describe('Inventory Controller', function() {
expect(user.items.currentPet).to.eql('Cactus-Base');
});
it('purchases an egg', function(){
scope.purchase('eggs', window.habitrpgShared.content.eggs['Wolf']);
it('purchases an egg', inject(function(Content){
scope.purchase('eggs', Content.eggs['Wolf']);
expect(user.balance).to.eql(3.25);
expect(user.items.eggs).to.eql({Cactus: 1, Wolf: 1})
});
}));
});