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

Commit fe6247a

Browse files
siddiibtford
authored andcommitted
docs(guide/unit-testing): add expression example
* Improved developer guide, directive unit testing documentation code with scope expression * Removed documentation block with nothing on it
1 parent 2b90ef1 commit fe6247a

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

docs/content/guide/dev_guide.unit-testing.ngdoc

+7-19
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,14 @@ app.directive('aGreatEye', function () {
295295
return {
296296
restrict: 'E',
297297
replace: true,
298-
template: '<h1>lidless, wreathed in flame</h1>'
298+
template: '<h1>lidless, wreathed in flame, {{1 + 1}} times</h1>'
299299
};
300300
});
301301
</pre>
302302

303303
This directive is used as a tag `<a-great-eye></a-great-eye>`. It replaces the entire tag with the
304-
template `<h1>lidless, wreathed in flame</h1>`. Now we are going to write a jasmine unit test to
305-
verify this functionality.
304+
template `<h1>lidless, wreathed in flame, {{1 + 1}} times</h1>`. Now we are going to write a jasmine unit test to
305+
verify this functionality. Note that the expression `{{1 + 1}}` times will also be evaluated in the rendered content.
306306

307307
<pre>
308308
describe('Unit testing great quotes', function() {
@@ -323,30 +323,18 @@ describe('Unit testing great quotes', function() {
323323
it('Replaces the element with the appropriate content', function() {
324324
// Compile a piece of HTML containing the directive
325325
var element = $compile("<a-great-eye></a-great-eye>")($rootScope);
326+
// fire all the watches, so the scope expression {{1 + 1}} will be evaluated
327+
$rootScope.$digest();
326328
// Check that the compiled element contains the templated content
327-
expect(element.html()).toContain("lidless, wreathed in flame");
329+
expect(element.html()).toContain("lidless, wreathed in flame, 2 times");
328330
});
329331
});
330332
</pre>
331333

332334
We inject the $compile service and $rootScope before each jasmine test. The $compile service is used
333335
to render the aGreatEye directive. After rendering the directive we ensure that the directive has
334-
replaced the content and "lidless, wreathed in flame" is present.
336+
replaced the content and "lidless, wreathed in flame, 2 times" is present.
335337

336-
## Mocks
337-
oue
338-
339-
## Global State Isolation
340-
oue
341-
342-
# Preferred way of Testing
343-
uo
344-
345-
## JavaScriptTestDriver
346-
ou
347-
348-
## Jasmine
349-
ou
350338

351339
## Sample project
352340
See the {@link https://github.com/angular/angular-seed angular-seed} project for an example.

0 commit comments

Comments
 (0)