Last active
January 27, 2016 12:27
-
-
Save sscovil/c64879bd7b527dd0dfd3 to your computer and use it in GitHub Desktop.
For SO question: http://stackoverflow.com/questions/35035924/how-to-do-unit-testing-using-jasmine-on-that-factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('behaviour', []) | |
.factory('behaviours', behavioursFactory) | |
; | |
behavioursFactory.$inject = ['$http']; | |
function behavioursFactory($http) { | |
var behaviours; | |
$http.get('data.json').then(function(res) { | |
behaviours = res.data; | |
}, function(err) { | |
/* hanlde http error */ | |
}); | |
return { | |
get: function(name) { | |
if (!behaviours) { | |
/* http request failed or is still in progress */ | |
} else if (behaviours[name]) { | |
/* behaviour exists, do something */ | |
} else { | |
/* no behaviour with given name */ | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it tells me that behaviours[name] is not an object and it's undefined ?