Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 85880a6

Browse files
committed
feat(testability): add $$testability service
The $$testability service is a collection of methods for use when debugging or by automated testing tools. It is available globally through the function `angular.getTestability`. For reference, see the Angular.Dart version at dart-archive/angular.dart#1191
1 parent 46343c6 commit 85880a6

File tree

15 files changed

+327
-16
lines changed

15 files changed

+327
-16
lines changed

angularFiles.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var angularFiles = {
3535
'src/ng/sce.js',
3636
'src/ng/sniffer.js',
3737
'src/ng/templateRequest.js',
38+
'src/ng/testability.js',
3839
'src/ng/timeout.js',
3940
'src/ng/urlUtils.js',
4041
'src/ng/window.js',

docs/content/guide/expression.ngdoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ the method from your view. If you want to `eval()` an Angular expression yoursel
3838
## Example
3939
<example>
4040
<file name="index.html">
41-
1+2={{1+2}}
41+
<span>
42+
1+2={{1+2}}
43+
</span>
4244
</file>
4345

4446
<file name="protractor.js" type="protractor">

docs/content/guide/module.ngdoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ I'm in a hurry. How do I get a Hello World module working?
5050

5151
<file name="protractor.js" type="protractor">
5252
it('should add Hello to the name', function() {
53-
expect(element(by.binding(" 'World' | greet ")).getText()).toEqual('Hello, World!');
53+
expect(element(by.binding("'World' | greet")).getText()).toEqual('Hello, World!');
5454
});
5555
</file>
5656
</example>
@@ -128,7 +128,7 @@ The above is a suggestion. Tailor it to your needs.
128128

129129
<file name="protractor.js" type="protractor">
130130
it('should add Hello to the name', function() {
131-
expect(element(by.binding(" greeting ")).getText()).toEqual('Bonjour World!');
131+
expect(element(by.binding("greeting")).getText()).toEqual('Bonjour World!');
132132
});
133133
</file>
134134

npm-shrinkwrap.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"karma-sauce-launcher": "0.2.0",
3434
"karma-script-launcher": "0.1.0",
3535
"karma-browserstack-launcher": "0.0.7",
36-
"protractor": "1.0.0",
36+
"protractor": "1.2.0-beta1",
3737
"yaml-js": "~0.0.8",
3838
"rewire": "1.1.3",
3939
"promises-aplus-tests": "~2.0.4",

src/.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"encodeUriQuery": false,
8080
"angularInit": false,
8181
"bootstrap": false,
82+
"getTestability": false,
8283
"snake_case": false,
8384
"bindJQuery": false,
8485
"assertArg": false,

src/Angular.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
encodeUriQuery: true,
7575
angularInit: true,
7676
bootstrap: true,
77+
getTestability: true,
7778
snake_case: true,
7879
bindJQuery: true,
7980
assertArg: true,
@@ -1459,6 +1460,18 @@ function reloadWithDebugInfo() {
14591460
window.location.reload();
14601461
}
14611462

1463+
/*
1464+
* @name angular.getTestability
1465+
* @module ng
1466+
* @description
1467+
* Get the testability service for the instance of Angular on the given
1468+
* element.
1469+
* @param {DOMElement} element DOM element which is the root of angular application.
1470+
*/
1471+
function getTestability(rootElement) {
1472+
return angular.element(rootElement).injector().get('$$testability');
1473+
}
1474+
14621475
var SNAKE_CASE_REGEXP = /[A-Z]/g;
14631476
function snake_case(name, separator) {
14641477
separator = separator || '_';

src/AngularPublic.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
$SnifferProvider,
8080
$TemplateCacheProvider,
8181
$TemplateRequestProvider,
82+
$$TestabilityProvider,
8283
$TimeoutProvider,
8384
$$RAFProvider,
8485
$$AsyncCallbackProvider,
@@ -136,6 +137,7 @@ function publishExternalAPI(angular){
136137
'lowercase': lowercase,
137138
'uppercase': uppercase,
138139
'callbacks': {counter: 0},
140+
'getTestability': getTestability,
139141
'$$minErr': minErr,
140142
'$$csp': csp,
141143
'reloadWithDebugInfo': reloadWithDebugInfo
@@ -230,6 +232,7 @@ function publishExternalAPI(angular){
230232
$sniffer: $SnifferProvider,
231233
$templateCache: $TemplateCacheProvider,
232234
$templateRequest: $TemplateRequestProvider,
235+
$$testability: $$TestabilityProvider,
233236
$timeout: $TimeoutProvider,
234237
$window: $WindowProvider,
235238
$$rAF: $$RAFProvider,

src/ng/directive/input.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ var inputType = {
814814
</file>
815815
<file name="protractor.js" type="protractor">
816816
it('should change state', function() {
817-
var color = element(by.binding('color | json'));
817+
var color = element(by.binding('color'));
818818
819819
expect(color.getText()).toContain('blue');
820820
@@ -1313,7 +1313,7 @@ function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filt
13131313
</div>
13141314
</file>
13151315
<file name="protractor.js" type="protractor">
1316-
var user = element(by.binding('user'));
1316+
var user = element(by.exactBinding('user'));
13171317
var userNameValid = element(by.binding('myForm.userName.$valid'));
13181318
var lastNameValid = element(by.binding('myForm.lastName.$valid'));
13191319
var lastNameError = element(by.binding('myForm.lastName.$error'));
@@ -2542,7 +2542,7 @@ var minlengthDirective = function() {
25422542
* </file>
25432543
* <file name="protractor.js" type="protractor">
25442544
* var listInput = element(by.model('names'));
2545-
* var names = element(by.binding('names'));
2545+
* var names = element(by.exactBinding('names'));
25462546
* var valid = element(by.binding('myForm.namesInput.$valid'));
25472547
* var error = element(by.css('span.error'));
25482548
*
@@ -2572,7 +2572,7 @@ var minlengthDirective = function() {
25722572
* <file name="protractor.js" type="protractor">
25732573
* it("should split the text by newlines", function() {
25742574
* var listInput = element(by.model('list'));
2575-
* var output = element(by.binding(' list | json '));
2575+
* var output = element(by.binding('list | json'));
25762576
* listInput.sendKeys('abc\ndef\nghi');
25772577
* expect(output.getText()).toContain('[\n "abc",\n "def",\n "ghi"\n]');
25782578
* });

src/ng/directive/ngEventDirs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
<button ng-click="count = count + 1" ng-init="count=0">
2020
Increment
2121
</button>
22-
count: {{count}}
22+
<span>
23+
count: {{count}}
24+
</span>
2325
</file>
2426
<file name="protractor.js" type="protractor">
2527
it('should check ng-click', function() {

0 commit comments

Comments
 (0)