in Angular applications
<script src="node_modules/angular/angular.js"></script>
<script>
angular.module('HelloApp', [])
.controller('HelloController', function ($scope) {
$scope.names = ['John', 'Mary'];
});
</script>
<body ng-app="HelloApp" ng-controller="HelloController">
<h2>Hello</h2>
<ul>
<li ng-repeat="name in names track by $index">{{ name }}</li>
</ul>
</body>
.controller('HelloController', function ($scope, $http) {
$scope.names = ['John', 'Mary'];
$scope.addName = function () {
$http.get('/new/name').then(function (newName) {
$scope.names.push(newName);
});
};
});
.controller('HelloController', function ($scope, $http) {
$scope.names = ['John', 'Mary'];
$scope.addName = function () {
$http.get('/new/name').then(function (newName) {
$scope.names.push(newName);
});
};
});
// app.js
angular.module('HelloApp', [])
.controller('HelloController', function ($scope) {
$scope.names = ['John', 'Mary'];
});
// spec.js
ngDescribe({
modules: 'HelloApp',
controller: 'HelloController',
tests: function (deps) {
it('has names', function () {
expect(deps.names).toEqual(['John', 'Mary']);
});
});
});
(function () {
function nextName() {
return 'World';
}
angular.module('HelloApp', [])
.controller('HelloController', function ($scope) {
$scope.names = ['John', 'Mary'];
$scope.addName = function () {
$scope.names.push(nextName());
};
});
}());
How do we test 'nextName()' ?
// next-name-spec.js
var ngDice = require('ng-dice');
ngDice({
name: 'app',
file: __dirname + '/app.js',
extract: 'nextName()',
tests: function (codeExtract) {
it('returns next name', function () {
var nextName = codeExtract();
console.assert(nextName() === 'World');
});
}
});
built on top of really-need and describe-it