var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.$watch('$viewContentLoaded', function() {
$scope.variableOne= true;
});
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker jasmine testing</title>
<link data-require="jasmine" data-semver="1.3.1" rel="stylesheet" href="//cdn.jsdelivr.net/jasmine/1.3.1/jasmine.css" />
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="jasmine" src="//cdn.jsdelivr.net/jasmine/1.3.1/jasmine.js" data-semver="1.3.1"></script>
<script data-require="jasmine" src="//cdn.jsdelivr.net/jasmine/1.3.1/jasmine-html.js" data-semver="1.3.1"></script>
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.8/angular.js" data-semver="1.4.8"></script>
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.8/angular-mocks.js" data-semver="1.4.8"></script>
<script src="app.js"></script>
<script src="app.spec.js"></script>
<script src="jasmineBootstrap.js"></script>
</head>
<body>
<div id="container">
</div>
<div id="HTMLReporter" class="jasmine_reporter"></div>
</body>
</html>
/* restore "body" styling that were changes by "jasmine.css"... */
body { background-color: white; padding: 0; margin: 8px; }
/* ... but remain the "jasmine.css" styling for the Jasmine reporting */
.jasmine_reporter { background-color: #eeeeee; padding: 0; margin: 0; }
describe('plunkr testing for angularjs and jasmine', function() {
describe('for the controller', function() {
beforeEach(module('plunker'));
beforeEach(module(function ($provide) {
$provide.value('$scope', {
$watch: jasmine.createSpy('$scope.$watch'),
$digest: jasmine.createSpy('$scope.$on')
})
}));
describe('Testing $viewContentLoaded', function() {
it('should be true', inject(function ($controller,$scope) {
$controller('MainCtrl');
// what to do to invoke $viewContentLoaded ???
$scope.$digest();
expect($scope.variableOne).toBe(true);
}));
});
});
});
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 250;
/**
Create the `HTMLReporter`, which Jasmine calls to provide results of each spec and each suite. The Reporter is responsible for presenting results to the user.
*/
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
/**
Delegate filtering of specs to the reporter. Allows for clicking on single suites or specs in the results to only run a subset of the suite.
*/
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
/**
Run all of the tests when the page finishes loading - and make sure to run any previous `onload` handler
### Test Results
Scroll down to see the results of all of these specs.
*/
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
//document.querySelector('.version').innerHTML = jasmineEnv.versionString();
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();