Skip to content

Commit 2ab4fde

Browse files
bripkenspetebacondarwin
authored andcommitted
docs(guide): add API documentation for ngScenario matchers
Matchers are briefly mentioned in the e2e test guide, but there is no documentation for the available matchers.
1 parent 1c77413 commit 2ab4fde

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ the test frame.
9797
Asserts the value of the given `future` satisfies the `matcher`. All API statements return a
9898
`future` object, which get a `value` assigned after they are executed. Matchers are defined using
9999
`angular.scenario.matcher`, and they use the value of futures to run the expectation. For example:
100-
`expect(browser().location().href()).toEqual('http://www.google.com')`
100+
`expect(browser().location().href()).toEqual('http://www.google.com')`. Available matchers
101+
are presented further down this document.
101102

102103
## expect(future).not().{matcher}
103104
Asserts the value of the given `future` satisfies the negation of the `matcher`.
@@ -177,6 +178,43 @@ come with almost no-help from the compiler. For this reason we feel very strongl
177178
written in JavaScript needs to come with a strong set of tests. We have built many features into
178179
angular which makes testing your angular applications easy. So there is no excuse for not testing.
179180

181+
# Matchers
182+
183+
Matchers are used in combination with the `expect(...)` function as described above and can
184+
be negated with `not()`. For instance: `expect(element('h1').text()).not().toEqual('Error')`.
185+
186+
Source: {@link https://github.com/angular/angular.js/blob/master/src/ngScenario/matchers.js}
187+
188+
<pre>
189+
// value and Object comparison following the rules of angular.equals().
190+
expect(value).toEqual(value)
191+
192+
// a simpler value comparison using ===
193+
expect(value).toBe(value)
194+
195+
// checks that the value is defined by checking its type.
196+
expect(value).toBeDefined()
197+
198+
// the following two matchers are using JavaScript's standard truthiness rules
199+
expect(value).toBeTruthy()
200+
expect(value).toBeFalsy()
201+
202+
// verify that the value matches the given regular expression. The regular
203+
// expression may be passed in form of a string or a regular expression
204+
// object.
205+
expect(value).toMatch(expectedRegExp)
206+
207+
// a check for null using ===
208+
expect(value).toBeNull()
209+
210+
// Array.indexOf(...) is used internally to check whether the element is
211+
// contained within the array.
212+
expect(value).toContain(expected)
213+
214+
// number comparison using < and >
215+
expect(value).toBeLessThan(expected)
216+
expect(value).toBeGreaterThan(expected)
217+
</pre>
180218

181219
# Example
182220
See the {@link angular-seed https://github.com/angular/angular-seed} project for an example.

0 commit comments

Comments
 (0)