You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/conditional-rendering.md
+13-6
Original file line number
Diff line number
Diff line change
@@ -50,21 +50,26 @@ If `get()` does not return an element matching the selector, it will raise an er
50
50
51
51
## Using `find()` and `exists()`
52
52
53
-
`get()` works for asserting elements do exist, because it throws an error when it can't find an element, you can't use it to assert elements don't exist. For this, we can use `find()` and `exists()`. The next test asserts that if `admin` is `false` (which is it by default), the admin link is not present:
53
+
`get()` works for asserting elements do exist. However, as we mentioned, it throws an error when it can't find an element, so you can't use it to assert whether if elements exist.
54
+
55
+
To do so, we use `find()` and `exists()`. The next test asserts that if `admin` is `false` (which is it by default), the admin link is not present:
54
56
55
57
```js
56
58
test('does not render an admin link', () => {
57
59
constwrapper=mount(Nav)
58
-
constadminLink=wrapper.find('#admin')
59
-
expect(adminLink.exists()).toBe(false)
60
+
61
+
// Using `wrapper.get` would throw and make the test fail.
Notice we are calling `exists()` on the value returned from `.find()`? `find()`, like `mount()`, also returns a wrapper, similar to `mount()`. `mount()` has a few extra methods, because it's wrapping a Vue component, and `find()` only returns a regular DOM node, but many of the methods are shared between both. Some other methods include `classes()`, which gets the classes a DOM node has, and `trigger()` for simulating user interaction. You can find a list of methods supported [here](/api/#wrapper-methods).
64
67
65
68
## Using `data`
66
69
67
-
The final test is to assert that the admin link is rendered when `admin` is `true`. It's default by `false`, but we can override that using the second argument to `mount()`, the [`mounting options`](/api/#mount-options). For `data`, we use the aptly named `data` option:
70
+
The final test is to assert that the admin link is rendered when `admin` is `true`. It's `false` by default, but we can override that using the second argument to `mount()`, the [`mounting options`](/api/#mount-options).
0 commit comments