Angular unit tests exercise
Angular unit tests exercise.
Implement the failing tests
HTML
<script src="http://jasmine.github.io/1.3/lib/jasmine.js"></script>
<script src="http://jasmine.github.io/1.3/lib/jasmine-html.js"></script>
<link rel="stylesheet" href="http://jasmine.github.io/1.3/lib/jasmine.css">
<script src="http://code.angularjs.org/1.2.9/angular.js"></script>
<script src="http://code.angularjs.org/1.2.9/angular-mocks.js"></script>
JavaScript
//--- CODE --------------------------
var myApp = angular.module('myApp', []);
myApp.service('mySrv', [function () {
// Converts name from camelCase to snake-case
this.camelToSnakeCase = function (camelCase) {
return camelCase.replace(/[A-Z]/g, function (match, pos) {
return (pos > 0 ? '-' : '') + match.toLowerCase();
});
}
}]);
myApp.controller('myCtrl', ['$scope', 'mySrv', function ($scope, mySrv) {
$scope.name = 'angular-js';
$scope.setName = function (name) {
$scope.name = mySrv.camelToSnakeCase(name);
};
}]);
myApp.directive('myDrtv', function () {
return {
restrict: 'E',
scope: {
name: '='
},
// Better to externalize to templateUrl, this is for demonstration sake
template: '<div>Hello {{name}}</div>',
replace: false
};
});
// ---SPECS-------------------------
describe('mySrv', function () {
var service;
beforeEach(function () {
this.fail(Error('Setup myApp injections and inject service'));
});
it('transforms camelCase to snake-case', function () {
this.fail(Error('implement me!'));
});
it('retains does not change snake-case input', function () {
this.fail(Error('implement me!'));
});
it('does not add a dash to a work starting with upper case char', function () {
this.fail(Error('implement me!'));
});
});
describe('myCtrl', function () {
var controller,
mySrvSpy,
scope;
beforeEach(function () {
this.fail(Error('Setup myApp injections, spy service dependency and create controller instance'));
});
it('sets a deafult name', function () {
this.fail(Error('implement me!'));
});
it('updates the name with snake-case', function () {
this.fail(Error('implement me!'));
});
});
describe('myDrtv', function () {
var element,
name = 'Homer';
beforeEach(function () {
...