diff options
| author | Misko Hevery | 2012-03-23 14:03:24 -0700 |
|---|---|---|
| committer | Misko Hevery | 2012-03-28 11:16:35 -0700 |
| commit | 2430f52bb97fa9d682e5f028c977c5bf94c5ec38 (patch) | |
| tree | e7529b741d70199f36d52090b430510bad07f233 /test/ng/directive/ngBindSpec.js | |
| parent | 944098a4e0f753f06b40c73ca3e79991cec6c2e2 (diff) | |
| download | angular.js-2430f52bb97fa9d682e5f028c977c5bf94c5ec38.tar.bz2 | |
chore(module): move files around in preparation for more modules
Diffstat (limited to 'test/ng/directive/ngBindSpec.js')
| -rw-r--r-- | test/ng/directive/ngBindSpec.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/test/ng/directive/ngBindSpec.js b/test/ng/directive/ngBindSpec.js new file mode 100644 index 00000000..01a07c52 --- /dev/null +++ b/test/ng/directive/ngBindSpec.js @@ -0,0 +1,80 @@ +'use strict'; + +describe('ng-bind-*', function() { + var element; + + + afterEach(function() { + dealoc(element); + }); + + + describe('ng-bind', function() { + + it('should set text', inject(function($rootScope, $compile) { + element = $compile('<div ng-bind="a"></div>')($rootScope); + expect(element.text()).toEqual(''); + $rootScope.a = 'misko'; + $rootScope.$digest(); + expect(element.hasClass('ng-binding')).toEqual(true); + expect(element.text()).toEqual('misko'); + })); + + it('should set text to blank if undefined', inject(function($rootScope, $compile) { + element = $compile('<div ng-bind="a"></div>')($rootScope); + $rootScope.a = 'misko'; + $rootScope.$digest(); + expect(element.text()).toEqual('misko'); + $rootScope.a = undefined; + $rootScope.$digest(); + expect(element.text()).toEqual(''); + $rootScope.a = null; + $rootScope.$digest(); + expect(element.text()).toEqual(''); + })); + + it('should set html', inject(function($rootScope, $compile) { + element = $compile('<div ng-bind-html="html"></div>')($rootScope); + $rootScope.html = '<div unknown>hello</div>'; + $rootScope.$digest(); + expect(lowercase(element.html())).toEqual('<div>hello</div>'); + })); + + it('should set unsafe html', inject(function($rootScope, $compile) { + element = $compile('<div ng-bind-html-unsafe="html"></div>')($rootScope); + $rootScope.html = '<div onclick="">hello</div>'; + $rootScope.$digest(); + expect(lowercase(element.html())).toEqual('<div onclick="">hello</div>'); + })); + + it('should suppress rendering of falsy values', inject(function($rootScope, $compile) { + element = $compile('<div>{{ null }}{{ undefined }}{{ "" }}-{{ 0 }}{{ false }}</div>')($rootScope); + $rootScope.$digest(); + expect(element.text()).toEqual('-0false'); + })); + + it('should render object as JSON ignore $$', inject(function($rootScope, $compile) { + element = $compile('<div>{{ {key:"value", $$key:"hide"} }}</div>')($rootScope); + $rootScope.$digest(); + expect(fromJson(element.text())).toEqual({key:'value'}); + })); + }); + + + describe('ng-bind-template', function() { + + it('should ng-bind-template', inject(function($rootScope, $compile) { + element = $compile('<div ng-bind-template="Hello {{name}}!"></div>')($rootScope); + $rootScope.name = 'Misko'; + $rootScope.$digest(); + expect(element.hasClass('ng-binding')).toEqual(true); + expect(element.text()).toEqual('Hello Misko!'); + })); + + it('should render object as JSON ignore $$', inject(function($rootScope, $compile) { + element = $compile('<pre>{{ {key:"value", $$key:"hide"} }}</pre>')($rootScope); + $rootScope.$digest(); + expect(fromJson(element.text())).toEqual({key:'value'}); + })); + }); +}); |
