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

Commit 4179f62

Browse files
siddiichirayuk
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 f4c6b2c commit 4179f62

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
@@ -294,14 +294,14 @@ app.directive('aGreatEye', function () {
294294
return {
295295
restrict: 'E',
296296
replace: true,
297-
template: '<h1>lidless, wreathed in flame</h1>'
297+
template: '<h1>lidless, wreathed in flame, {{1 + 1}} times</h1>'
298298
};
299299
});
300300
</pre>
301301

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

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

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

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

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

0 commit comments

Comments
 (0)