Skip to content

Instantly share code, notes, and snippets.

@nakamura-to
Created November 7, 2014 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakamura-to/bd9e675b704a90361883 to your computer and use it in GitHub Desktop.
Save nakamura-to/bd9e675b704a90361883 to your computer and use it in GitHub Desktop.
A Pen by Toshihiro Nakamura.
<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);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment