Skip to content

Commit 204210d

Browse files
Update tests for set-property and set-attribute commands
1 parent f218052 commit 204210d

File tree

8 files changed

+38
-4
lines changed

8 files changed

+38
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
instructions = [
2+
"""const parseSetAttributeElem = await page.$(\"a\");
3+
if (parseSetAttributeElem === null) { throw '\"a\" not found'; }
4+
await page.evaluate(e => {
5+
e.removeAttribute(\"b\");
6+
}, parseSetAttributeElem);""",
7+
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
error = """type \"json\" (`{\"a\": \"x\"}`) is not allowed as value in this JSON dict, allowed types are: [`ident`, `number`, `string`] (second element of the tuple)"""
1+
error = """type \"json\" (`{\"a\": \"x\"}`) is not allowed as value in this JSON dict, allowed types are: [`boolean`, `ident`, `number`, `string`] (second element of the tuple)"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
error = """type \"array\" (`[\"a\"]`) is not allowed as value in this JSON dict, allowed types are: [`ident`, `number`, `string`] (second element of the tuple)"""
1+
error = """type \"array\" (`[\"a\"]`) is not allowed as value in this JSON dict, allowed types are: [`boolean`, `ident`, `number`, `string`] (second element of the tuple)"""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error = """type \"boolean\" (`true`) is not allowed as value in this JSON dict, allowed types are: [`number`, `string`] (second element of the tuple)"""
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
instructions = [
2+
"""const parseSetPropertyElem = await page.$(\"a\");
3+
if (parseSetPropertyElem === null) { throw '\"a\" not found'; }
4+
await page.evaluate(e => {
5+
function setObjValue(object, path, value) {
6+
for (let i = 0; i < path.length - 1; ++i) {
7+
const subPath = path[i];
8+
if (object[subPath] === undefined || object[subPath] === null) {
9+
if (value === undefined) {
10+
return;
11+
}
12+
object[subPath] = {};
13+
}
14+
object = object[subPath];
15+
}
16+
if (value === undefined) {
17+
delete object[path[path.length - 1]];
18+
} else {
19+
object[path[path.length - 1]] = value;
20+
}
21+
}
22+
setObjValue(e, [\"b\"], true);
23+
}, parseSetPropertyElem);""",
24+
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
error = """type \"json\" (`{\"a\": \"x\"}`) is not allowed as value in this JSON dict, allowed types are: [`ident`, `number`, `string`] (second element of the tuple)"""
1+
error = """type \"json\" (`{\"a\": \"x\"}`) is not allowed as value in this JSON dict, allowed types are: [`boolean`, `ident`, `number`, `string`] (second element of the tuple)"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
error = """type \"array\" (`[\"a\"]`) is not allowed as value in this JSON dict, allowed types are: [`ident`, `number`, `string`] (second element of the tuple)"""
1+
error = """type \"array\" (`[\"a\"]`) is not allowed as value in this JSON dict, allowed types are: [`boolean`, `ident`, `number`, `string`] (second element of the tuple)"""

tools/api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ function checkAttributeProperty(x, func) {
557557
func('("a", {"b": "c", "d": "e"})', 'basic-4');
558558
func('("a", {"b": null})', 'basic-5');
559559
func('("a", {"b": null, "a": "b"})', 'basic-6');
560+
// This one will fail for `set-css`.
561+
func('("a", {"b": true})', 'basic-7');
560562

561563
// XPath
562564
func('("/a", "b", "c")', 'xpath-1');

0 commit comments

Comments
 (0)