'use strict';
describe('ngBind*', function() {
var element;
afterEach(function() {
dealoc(element);
});
describe('ngBind', function() {
it('should set text', inject(function($rootScope, $compile) {
element = $compile('
')($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('')($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 suppress rendering of falsy values', inject(function($rootScope, $compile) {
element = $compile('' +
'' +
'-' +
'' +
'' +
'
')($rootScope);
$rootScope.$digest();
expect(element.text()).toEqual('-0false');
}));
});
describe('ngBindTemplate', function() {
it('should ngBindTemplate', inject(function($rootScope, $compile) {
element = $compile('')($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('{{ {key:"value", $$key:"hide"} }}')($rootScope);
$rootScope.$digest();
expect(fromJson(element.text())).toEqual({key:'value'});
}));
});
describe('ngBindHtml', function() {
describe('SCE disabled', function() {
beforeEach(function() {
module(function($sceProvider) { $sceProvider.enabled(false); });
});
it('should set html', inject(function($rootScope, $compile) {
element = $compile('')($rootScope);
$rootScope.html = 'hello
';
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('hello
');
}));
});
describe('SCE enabled', function() {
it('should NOT set html for untrusted values', inject(function($rootScope, $compile) {
element = $compile('')($rootScope);
$rootScope.html = 'hello
';
expect($rootScope.$digest).toThrow();
}));
it('should NOT set html for wrongly typed values', inject(function($rootScope, $compile, $sce) {
element = $compile('')($rootScope);
$rootScope.html = $sce.trustAsCss('hello
');
expect($rootScope.$digest).toThrow();
}));
it('should set html for trusted values', inject(function($rootScope, $compile, $sce) {
element = $compile('')($rootScope);
$rootScope.html = $sce.trustAsHtml('hello
');
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('hello
');
}));
describe('when $sanitize is available', function() {
beforeEach(function() { module('ngSanitize'); });
it('should sanitize untrusted html', inject(function($rootScope, $compile) {
element = $compile('')($rootScope);
$rootScope.html = 'hello
';
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('hello
');
}));
});
});
});
});