'use strict'; describe('$$testability', function() { describe('finding elements', function() { var $$testability, $compile, scope, element; beforeEach(inject(function(_$$testability_, _$compile_, $rootScope) { $$testability = _$$testability_; $compile = _$compile_; scope = $rootScope.$new(); })); afterEach(function() { dealoc(element); }); it('should find partial bindings', function() { element = '
' + ' {{name}}' + ' {{username}}' + '
'; element = $compile(element)(scope); var names = $$testability.findBindings(element[0], 'name'); expect(names.length).toBe(2); expect(names[0]).toBe(element.find('span')[0]); expect(names[1]).toBe(element.find('span')[1]); }); it('should find exact bindings', function() { element = '
' + ' {{name}}' + ' {{username}}' + '
'; element = $compile(element)(scope); var users = $$testability.findBindings(element[0], 'name', true); expect(users.length).toBe(1); expect(users[0]).toBe(element.find('span')[0]); }); it('should ignore filters for exact bindings', function() { element = '
' + ' {{name | uppercase}}' + ' {{username}}' + '
'; element = $compile(element)(scope); var users = $$testability.findBindings(element[0], 'name', true); expect(users.length).toBe(1); expect(users[0]).toBe(element.find('span')[0]); }); it('should ignore whitespace for exact bindings', function() { element = '
' + ' {{ name }}' + ' {{username}}' + '
'; element = $compile(element)(scope); var users = $$testability.findBindings(element[0], 'name', true); expect(users.length).toBe(1); expect(users[0]).toBe(element.find('span')[0]); }); it('should find bindings by class', function() { element = '
' + ' ' + ' {{username}}' + '
'; element = $compile(element)(scope); var names = $$testability.findBindings(element[0], 'name'); expect(names.length).toBe(2); expect(names[0]).toBe(element.find('span')[0]); expect(names[1]).toBe(element.find('span')[1]); }); it('should only search within the context element', function() { element = '
' + ' ' + ' ' + '
'; element = $compile(element)(scope); var names = $$testability.findBindings(element.find('ul')[0], 'name'); expect(names.length).toBe(1); expect(names[0]).toBe(element.find('li')[0]); }); it('should find bindings with allowed special characters', function() { element = '
' + ' {{$index}}' + ' {{foo.bar}}' + ' {{foonbar}}' + ' {{foo | uppercase}}' + '
'; element = $compile(element)(scope); var indexes = $$testability.findBindings(element[0], '$index', true); expect(indexes.length).toBe(1); expect(indexes[0]).toBe(element.find('span')[0]); var foobars = $$testability.findBindings(element[0], 'foo.bar', true); expect(foobars.length).toBe(1); // it should not match {{foonbar}} expect(foobars[0]).toBe(element.find('span')[1]); var foo = $$testability.findBindings(element[0], 'foo', true); expect(foo.length).toBe(1); // it should match {{foo | uppercase}} var uppercase = $$testability.findBindings(element[0], 'uppercase', true); expect(uppercase.length).toBe(1); // it should match {{foo | uppercase}} var filteredFoo = $$testability.findBindings(element[0], 'foo | uppercase', true); expect(filteredFoo.length).toBe(1); // it should match {{foo | uppercase}} expect(filteredFoo[0]).toBe(element.find('span')[3]); }); it('should find partial models', function() { element = '
' + ' ' + ' ' + '
'; element = $compile(element)(scope); var names = $$testability.findModels(element[0], 'name'); expect(names.length).toBe(2); expect(names[0]).toBe(element.find('input')[0]); expect(names[1]).toBe(element.find('input')[1]); }); it('should find exact models', function() { element = '
' + ' ' + ' ' + '
'; element = $compile(element)(scope); var users = $$testability.findModels(element[0], 'name', true); expect(users.length).toBe(1); expect(users[0]).toBe(element.find('input')[0]); }); it('should find models in different input types', function() { element = '
' + ' ' + '