Forked from Testing With Jasmine's Pen Jasmine 2.0.0 - Playground - JavaScript version.
A Pen by Toshihiro Nakamura on CodePen.
Forked from Testing With Jasmine's Pen Jasmine 2.0.0 - Playground - JavaScript version.
A Pen by Toshihiro Nakamura on CodePen.
<html> | |
<head> | |
<link rel="stylesheet" href="http://codepen.io/TestingWithJasmine/pen/Ftabq.css"/> | |
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine.js"></script> | |
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine-html.js"></script> | |
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/boot.js"></script> | |
<script type="text/javascript" src="http://codepen.io/TestingWithJasmine/pen/Ftabq.js" ></script> | |
<script type="text/javascript" | |
src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.1/angular.js"></script> | |
<script type="text/javascript" | |
src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.1/angular-mocks.js"></script> | |
</head> | |
<body></body> | |
</html> |
///////////////////////////////// | |
// Setup | |
// | |
var Component = (function() { | |
function Component() {} | |
Component.prototype.isActive = function() { | |
return true; | |
}; | |
return Component; | |
})(); | |
///////////////////////////////// | |
// Tests | |
// | |
describe("$watchCollection", function() { | |
var $rootScope; | |
beforeEach(inject(function (_$rootScope_) { | |
$rootScope = _$rootScope_; | |
})); | |
it("should watch plain object props", function() { | |
var count = 0; | |
var scope = $rootScope.$new(); | |
scope.person = {name: 'hoge', age:20}; | |
scope.$watchCollection("person", function (newValue, oldValue) { | |
count++; | |
}); | |
expect(count).toBe(0); | |
scope.$digest(); | |
expect(count).toBe(1); | |
scope.person.name = "fuga"; | |
scope.$digest(); | |
expect(count).toBe(2); | |
}); | |
}); |