5 lines
30 KiB
JSON
5 lines
30 KiB
JSON
|
{
|
||
|
"id": "guide/testing-utility-apis",
|
||
|
"title": "Testing Utility APIs",
|
||
|
"contents": "\n\n\n<div class=\"github-links\">\n <a href=\"https://github.com/angular/angular/edit/master/aio/content/guide/testing-utility-apis.md?message=docs%3A%20describe%20your%20change...\" aria-label=\"Suggest Edits\" title=\"Suggest Edits\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">mode_edit</i></a>\n</div>\n\n\n<div class=\"content\">\n <h1 id=\"testing-utility-apis\">Testing Utility APIs<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/testing-utility-apis#testing-utility-apis\"><i class=\"material-icons\">link</i></a></h1>\n<p>This page describes the most useful Angular testing features.</p>\n<p>The Angular testing utilities include the <code><a href=\"api/core/testing/TestBed\" class=\"code-anchor\">TestBed</a></code>, the <code><a href=\"api/core/testing/ComponentFixture\" class=\"code-anchor\">ComponentFixture</a></code>, and a handful of functions that control the test environment.\nThe <a href=\"guide/testing-utility-apis#testbed-api-summary\"><em>TestBed</em></a> and <a href=\"guide/testing-utility-apis#component-fixture-api-summary\"><em>ComponentFixture</em></a> classes are covered separately.</p>\n<p>Here's a summary of the stand-alone functions, in order of likely utility:</p>\n<table>\n <tbody><tr>\n <th>\n Function\n </th>\n <th>\n Description\n </th>\n </tr>\n <tr>\n <td style=\"vertical-align: top\">\n <code><a href=\"api/core/testing/waitForAsync\" class=\"code-anchor\">waitForAsync</a></code>\n </td>\n <td>\n<p> Runs the body of a test (<code>it</code>) or setup (<code>beforeEach</code>) function within a special <em>async test zone</em>.\nSee <a href=\"guide/testing-components-scenarios#waitForAsync\">discussion above</a>.</p>\n </td>\n </tr>\n <tr>\n <td style=\"vertical-align: top\">\n <code><a href=\"api/core/testing/fakeAsync\" class=\"code-anchor\">fakeAsync</a></code>\n </td>\n <td>\n<p> Runs the body of a test (<code>it</code>) within a special <em>fakeAsync test zone</em>, enabling\na linear control flow coding style. See <a href=\"guide/testing-components-scenarios#fake-async\">discussion above</a>.</p>\n </td>\n </tr>\n <tr>\n <td style=\"vertical-align: top\">\n <code><a href=\"api/core/testing/tick\" class=\"code-anchor\">tick</a></code>\n </td>\n <td>\n<p> Simulates the passage of time and the completion of pending asynchronous activities\nby flushing both <em>timer</em> and <em>micro-task</em> queues within the <em>fakeAsync test zone</em>.</p>\n <div class=\"alert is-helpful\">\n<p> The curious, dedicated reader might enjoy this lengthy blog post,\n<a href=\"https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/\">\"<em>Tasks, microtasks, queues and schedules</em>\"</a>.</p>\n </div>\n<p> Accepts an optional argument that moves the virtual clock forward\nby the specified number of milliseconds,\nclearing asynchronous activities scheduled within that timeframe.\nSee <a href=\"guide/testing-components-scenarios#tick\">discussion above</a>.</p>\n </td>\n </tr>\n <tr>\n <td style=\"vertical-align: top\">\n <code>inject</code>\n </td>\n <td>\n<p> Injects one or more services from the current <code><a href=\"api/core/testing/TestBed\" class=\"code-anchor\">TestBed</a></code> injector into a test function.\nIt cannot inject a service provided by the component itself.\nSee discussion of the <a href=\"guide/testing-components-scenarios#get-injected-services\">debugElement.injector</a>.</p>\n </td>\n </tr>\n <tr>\n <td style=\"vertical-align: top\">\n <code><a href=\"api/core/testing/discardPeriodicTasks\" class=\"code-anchor\">discardPeriodicTasks</a></code>\n </td>\n <td>\n<p> When a <code><a href=\"api/core/testing/fakeAsync\" class=\"code-anchor\">fakeAsync</a>()</code> test ends with pending timer event <em>tasks</em> (queued <code>setTimeOut</code> and <code>setInterval</code> callbacks),\nthe test fails with a clear error message.</p>\n<p>
|
||
|
}
|