aboutsummaryrefslogtreecommitdiffstats
path: root/docs/content/guide/dev_guide.scopes.internals.ngdoc
diff options
context:
space:
mode:
authorIgor Minar2012-01-15 23:28:10 -0800
committerIgor Minar2012-01-17 09:49:37 -0800
commit92af30ce6e99676c71c85bd08962b68629564908 (patch)
tree4adf4b56cbf7c9fb6ee9dee8f40dd16fb2199842 /docs/content/guide/dev_guide.scopes.internals.ngdoc
parent54581d36df74ac128a078aafb3e4b66e0b1599f3 (diff)
downloadangular.js-92af30ce6e99676c71c85bd08962b68629564908.tar.bz2
docs(*): various doc fixes
Diffstat (limited to 'docs/content/guide/dev_guide.scopes.internals.ngdoc')
-rw-r--r--docs/content/guide/dev_guide.scopes.internals.ngdoc52
1 files changed, 28 insertions, 24 deletions
diff --git a/docs/content/guide/dev_guide.scopes.internals.ngdoc b/docs/content/guide/dev_guide.scopes.internals.ngdoc
index ca510a21..66d57a9f 100644
--- a/docs/content/guide/dev_guide.scopes.internals.ngdoc
+++ b/docs/content/guide/dev_guide.scopes.internals.ngdoc
@@ -57,16 +57,18 @@ A property write will always write to the current scope. This means that a write
property within the scope it writes to, as shown in the following example.
<pre>
-var root = angular.module.ng.$rootScope.Scope();
-var child = root.$new();
-
-root.name = 'angular';
-expect(child.name).toEqual('angular');
-expect(root.name).toEqual('angular');
-
-child.name = 'super-heroic framework';
-expect(child.name).toEqual('super-heroic framework');
-expect(root.name).toEqual('angular');
+it('should inherit properties', inject(function($rootScope)) {
+ var root = $rootScope;
+ var child = root.$new();
+
+ root.name = 'angular';
+ expect(child.name).toEqual('angular');
+ expect(root.name).toEqual('angular');
+
+ child.name = 'super-heroic framework';
+ expect(child.name).toEqual('super-heroic framework');
+ expect(root.name).toEqual('angular');
+});
</pre>
@@ -172,8 +174,8 @@ doesn't need to worry about propagating the `$digest` call from the parent scope
This happens automatically.
## Scopes in unit-testing
-You can create scopes, including the root scope, in tests using the {@link api/angular.module.ng.$rootScope.Scope
-angular.module.ng.$rootScope.Scope()} API. This allows you to mimic the run-time environment and have full control over
+You can create scopes, including the root scope, in tests by having the $rootScope injected into
+your spec. This allows you to mimic the run-time environment and have full control over
the life cycle of the scope so that you can assert correct model transitions. Since these scopes
are created outside the normal compilation process, their life cycles must be managed by the test.
@@ -183,18 +185,20 @@ within the unit-tests.
<pre>
// example of a test
- var scope = angular.module.ng.$rootScope.Scope();
- scope.$watch('name', function(scope, name){
- scope.greeting = 'Hello ' + name + '!';
- });
-
- scope.name = 'angular';
- // The watch does not fire yet since we have to manually trigger the digest phase.
- expect(scope.greeting).toEqual(undefined);
-
- // manually trigger digest phase from the test
- scope.$digest();
- expect(scope.greeting).toEqual('Hello Angular!');
+ it('should trigger a watcher', inject(function($rootScope) {
+ var scope = $rootScope;
+ scope.$watch('name', function(scope, name){
+ scope.greeting = 'Hello ' + name + '!';
+ });
+
+ scope.name = 'angular';
+ // The watch does not fire yet since we have to manually trigger the digest phase.
+ expect(scope.greeting).toEqual(undefined);
+
+ // manually trigger digest phase from the test
+ scope.$digest();
+ expect(scope.greeting).toEqual('Hello Angular!');
+ }
</pre>