|
35 | 35 | <doc:example>
|
36 | 36 | <doc:source>
|
37 | 37 | <script>
|
38 |
| - function SettingsController() { |
| 38 | + function SettingsController1() { |
39 | 39 | this.name = "John Smith";
|
40 | 40 | this.contacts = [
|
41 | 41 | {type: 'phone', value: '408 555 1212'},
|
42 | 42 | {type: 'email', value: 'john.smith@example.org'} ];
|
43 | 43 | };
|
44 | 44 |
|
45 |
| - SettingsController.prototype.greet = function() { |
| 45 | + SettingsController1.prototype.greet = function() { |
46 | 46 | alert(this.name);
|
47 | 47 | };
|
48 | 48 |
|
49 |
| - SettingsController.prototype.addContact = function() { |
| 49 | + SettingsController1.prototype.addContact = function() { |
50 | 50 | this.contacts.push({type: 'email', value: 'yourname@example.org'});
|
51 | 51 | };
|
52 | 52 |
|
53 |
| - SettingsController.prototype.removeContact = function(contactToRemove) { |
| 53 | + SettingsController1.prototype.removeContact = function(contactToRemove) { |
54 | 54 | var index = this.contacts.indexOf(contactToRemove);
|
55 | 55 | this.contacts.splice(index, 1);
|
56 | 56 | };
|
57 | 57 |
|
58 |
| - SettingsController.prototype.clearContact = function(contact) { |
| 58 | + SettingsController1.prototype.clearContact = function(contact) { |
59 | 59 | contact.type = 'phone';
|
60 | 60 | contact.value = '';
|
61 | 61 | };
|
62 | 62 | </script>
|
63 |
| - <div ng-controller="SettingsController as settings"> |
| 63 | + <div id="ctrl-as-exmpl" ng-controller="SettingsController1 as settings"> |
64 | 64 | Name: <input type="text" ng-model="settings.name"/>
|
65 | 65 | [ <a href="" ng-click="settings.greet()">greet</a> ]<br/>
|
66 | 66 | Contact:
|
|
79 | 79 | </div>
|
80 | 80 | </doc:source>
|
81 | 81 | <doc:scenario>
|
82 |
| - it('should check controller', function() { |
83 |
| - expect(element('.doc-example-live div>:input').val()).toBe('John Smith'); |
84 |
| - expect(element('.doc-example-live li:nth-child(1) input').val()) |
| 82 | + it('should check controller as', function() { |
| 83 | + expect(element('#ctrl-as-exmpl>:input').val()).toBe('John Smith'); |
| 84 | + expect(element('#ctrl-as-exmpl li:nth-child(1) input').val()) |
85 | 85 | .toBe('408 555 1212');
|
86 |
| - expect(element('.doc-example-live li:nth-child(2) input').val()) |
| 86 | + expect(element('#ctrl-as-exmpl li:nth-child(2) input').val()) |
87 | 87 | .toBe('john.smith@example.org');
|
88 | 88 |
|
89 |
| - element('.doc-example-live li:first a:contains("clear")').click(); |
90 |
| - expect(element('.doc-example-live li:first input').val()).toBe(''); |
| 89 | + element('#ctrl-as-exmpl li:first a:contains("clear")').click(); |
| 90 | + expect(element('#ctrl-as-exmpl li:first input').val()).toBe(''); |
91 | 91 |
|
92 |
| - element('.doc-example-live li:last a:contains("add")').click(); |
93 |
| - expect(element('.doc-example-live li:nth-child(3) input').val()) |
| 92 | + element('#ctrl-as-exmpl li:last a:contains("add")').click(); |
| 93 | + expect(element('#ctrl-as-exmpl li:nth-child(3) input').val()) |
94 | 94 |
|
95 | 95 | });
|
96 | 96 | </doc:scenario>
|
97 | 97 | </doc:example>
|
98 |
| -
|
99 |
| -
|
100 |
| -
|
101 | 98 | <doc:example>
|
102 | 99 | <doc:source>
|
103 | 100 | <script>
|
104 |
| - function SettingsController($scope) { |
| 101 | + function SettingsController2($scope) { |
105 | 102 | $scope.name = "John Smith";
|
106 | 103 | $scope.contacts = [
|
107 | 104 | {type:'phone', value:'408 555 1212'},
|
|
126 | 123 | };
|
127 | 124 | }
|
128 | 125 | </script>
|
129 |
| - <div ng-controller="SettingsController"> |
| 126 | + <div id="ctrl-exmpl" ng-controller="SettingsController2"> |
130 | 127 | Name: <input type="text" ng-model="name"/>
|
131 | 128 | [ <a href="" ng-click="greet()">greet</a> ]<br/>
|
132 | 129 | Contact:
|
|
146 | 143 | </doc:source>
|
147 | 144 | <doc:scenario>
|
148 | 145 | it('should check controller', function() {
|
149 |
| - expect(element('.doc-example-live div>:input').val()).toBe('John Smith'); |
150 |
| - expect(element('.doc-example-live li:nth-child(1) input').val()) |
| 146 | + expect(element('#ctrl-exmpl>:input').val()).toBe('John Smith'); |
| 147 | + expect(element('#ctrl-exmpl li:nth-child(1) input').val()) |
151 | 148 | .toBe('408 555 1212');
|
152 |
| - expect(element('.doc-example-live li:nth-child(2) input').val()) |
| 149 | + expect(element('#ctrl-exmpl li:nth-child(2) input').val()) |
153 | 150 | .toBe('john.smith@example.org');
|
154 | 151 |
|
155 |
| - element('.doc-example-live li:first a:contains("clear")').click(); |
156 |
| - expect(element('.doc-example-live li:first input').val()).toBe(''); |
| 152 | + element('#ctrl-exmpl li:first a:contains("clear")').click(); |
| 153 | + expect(element('#ctrl-exmpl li:first input').val()).toBe(''); |
157 | 154 |
|
158 |
| - element('.doc-example-live li:last a:contains("add")').click(); |
159 |
| - expect(element('.doc-example-live li:nth-child(3) input').val()) |
| 155 | + element('#ctrl-exmpl li:last a:contains("add")').click(); |
| 156 | + expect(element('#ctrl-exmpl li:nth-child(3) input').val()) |
160 | 157 |
|
161 | 158 | });
|
162 | 159 | </doc:scenario>
|
|
0 commit comments