Skip to content

Commit 9e25151

Browse files
committed
Add regex support, update docs
1 parent 03d199c commit 9e25151

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

docs/API.md

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# API
22

3-
```xml
3+
```vue
44
<tests>
55
<test>
66
<set>
@@ -19,7 +19,7 @@
1919
<details>
2020
<summary>Details</summary>
2121

22-
```xml
22+
```vue
2323
<tests for="ComponentPath">
2424
```
2525

@@ -35,7 +35,7 @@ This is the path to the component, used when importing it into your tests. Webpa
3535
<details>
3636
<summary>Details</summary>
3737

38-
```xml
38+
```vue
3939
<test name="NameValue" BindingTarget="BindingValue">
4040
```
4141

@@ -55,13 +55,13 @@ Sets the data of your component to these values before running the test.
5555
The BindingTarget will be set to this value of the `context` variable in your `<script>` tag.
5656

5757
#### Examples:
58-
```xml
58+
```vue
5959
<test name="render app">
6060
```
61-
```xml
61+
```vue
6262
<test name="render message correctly" :props="myProps">
6363
```
64-
```xml
64+
```vue
6565
<test name="render data value correctly" :data="myData">
6666
```
6767

@@ -74,19 +74,19 @@ The BindingTarget will be set to this value of the `context` variable in your `<
7474
<details>
7575
<summary>Details</summary>
7676

77-
```xml
77+
```vue
7878
<set selector="SelectorValue" value="Value" />
7979
```
8080

8181
Sets form input (text or select) value to Value.
8282

8383
#### Examples:
8484

85-
```xml
85+
```vue
8686
<set selector="input.first-name" value="Bob" />
8787
```
8888

89-
```xml
89+
```vue
9090
<set selector="select.title" value="Mr." />
9191
```
9292

@@ -99,19 +99,19 @@ Sets form input (text or select) value to Value.
9999
<details>
100100
<summary>Details</summary>
101101

102-
```xml
102+
```vue
103103
<trigger selector="SelectorValue" event="EventValue" />
104104
```
105105

106106
Triggers event named EventValue on the element(s) returned by SelectorValue.
107107

108108
#### Examples:
109109

110-
```xml
110+
```vue
111111
<trigger selector=".new-todo" event="keyup.enter" />
112112
```
113113

114-
```xml
114+
```vue
115115
<trigger selector=".el-select" event="change" />
116116
```
117117

@@ -124,7 +124,7 @@ Triggers event named EventValue on the element(s) returned by SelectorValue.
124124
<details>
125125
<summary>Details</summary>
126126

127-
```xml
127+
```vue
128128
<expect ReturnValue Matcher="MatchedValue" />
129129
```
130130

@@ -152,10 +152,18 @@ Match html of the selector.
152152

153153
Matches value as a substring of the matcher content.
154154

155+
#### `:to-match`
156+
157+
Same as above but with bindings. Pass context variable key name or regex.
158+
155159
#### `to-equal`
156160

157161
Matches value exactly on the matcher content.
158162

163+
#### `:to-equal`
164+
165+
Same as above but with bindings. Pass context variable key name or regex.
166+
159167
#### `to-be-truthy`
160168

161169
Matches anything that an "if" statement treats as true.
@@ -178,19 +186,31 @@ Matches if value is null.
178186

179187
#### Examples:
180188

181-
```xml
189+
```vue
182190
<expect html to-match="Welcome!" />
183191
```
184192

185-
```xml
193+
```vue
186194
<expect text-of=".todo-list li" to-match="First" />
187195
```
188196

189-
```xml
197+
```vue
198+
<expect text-of=".todo-list li" :to-match="/F.*t/" />
199+
```
200+
201+
```vue
202+
<expect text-of=".todo-list li" :to-match="myMatchValue" />
203+
204+
<script>
205+
let context = { myMatchValue: 'First' }
206+
</script>
207+
```
208+
209+
```vue
190210
<expect text-of=".todo-list" to-be-falsy />
191211
```
192212

193-
```xml
213+
```vue
194214
<expect html to-match="Welcome!">
195215
<html>
196216
<h1> foo </h1>
@@ -207,7 +227,7 @@ Matches if value is null.
207227
<details>
208228
<summary>Details</summary>
209229

210-
```xml
230+
```vue
211231
<script>
212232
let context = {...}
213233
</script>
@@ -218,7 +238,7 @@ The contents of the `<script>` tag are executed before your tests start.
218238
The special `context` variable is where bindings connect to your data; e.g. `:props="myProps"` sets your component's props to whatever is in `context.myProps`. This must be defined if you are using bindings.
219239

220240
#### Examples:
221-
```xml
241+
```vue
222242
<script>
223243
let context = {
224244
myProps: {

src/generate/expect.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ function generateExpect(expect) {
4141
}
4242
else if (expect.$[':to-match']) {
4343
comparisonFn = 'toMatch';
44-
expectedValue = 'context.' + expect.$[':to-match'];
44+
let matchBindingValue = expect.$[':to-match'];
45+
expectedValue = matchBindingValue.startsWith('/') ? '' : 'context.';
46+
expectedValue += matchBindingValue
4547
}
4648
else if (expect.$['to-match']) {
4749
comparisonFn = 'toMatch';

0 commit comments

Comments
 (0)