Add error message checking
This commit is contained in:
parent
174a942e07
commit
7e1e7d59cd
@ -68,28 +68,28 @@ function testGetProperty2() {
|
|||||||
const accessor = new ObjectPropertyAccessor(object);
|
const accessor = new ObjectPropertyAccessor(object);
|
||||||
|
|
||||||
const data = [
|
const data = [
|
||||||
[0],
|
[[0], 'Invalid path: [0]'],
|
||||||
['0', 'invalid'],
|
[['0', 'invalid'], 'Invalid path: ["0"].invalid'],
|
||||||
['invalid'],
|
[['invalid'], 'Invalid path: invalid'],
|
||||||
['value1', 'invalid'],
|
[['value1', 'invalid'], 'Invalid path: value1.invalid'],
|
||||||
['value1', 'value2', 'invalid'],
|
[['value1', 'value2', 'invalid'], 'Invalid path: value1.value2.invalid'],
|
||||||
['value1', 'value2', 0],
|
[['value1', 'value2', 0], 'Invalid path: value1.value2[0]'],
|
||||||
['value1', 'value3', 'invalid'],
|
[['value1', 'value3', 'invalid'], 'Invalid path: value1.value3.invalid'],
|
||||||
['value1', 'value3', 0],
|
[['value1', 'value3', 0], 'Invalid path: value1.value3[0]'],
|
||||||
['value1', 'value4', 'invalid'],
|
[['value1', 'value4', 'invalid'], 'Invalid path: value1.value4.invalid'],
|
||||||
['value1', 'value4', 0],
|
[['value1', 'value4', 0], 'Invalid path: value1.value4[0]'],
|
||||||
['value5', 'length'],
|
[['value5', 'length'], 'Invalid path: value5.length'],
|
||||||
['value5', 0, 'invalid'],
|
[['value5', 0, 'invalid'], 'Invalid path: value5[0].invalid'],
|
||||||
['value5', 0, 0],
|
[['value5', 0, 0], 'Invalid path: value5[0][0]'],
|
||||||
['value5', 1, 'invalid'],
|
[['value5', 1, 'invalid'], 'Invalid path: value5[1].invalid'],
|
||||||
['value5', 1, 0],
|
[['value5', 1, 0], 'Invalid path: value5[1][0]'],
|
||||||
['value5', 2, 'invalid'],
|
[['value5', 2, 'invalid'], 'Invalid path: value5[2].invalid'],
|
||||||
['value5', 2, 0],
|
[['value5', 2, 0], 'Invalid path: value5[2][0]'],
|
||||||
['value5', 2.5]
|
[['value5', 2.5], 'Invalid index']
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const pathArray of data) {
|
for (const [pathArray, message] of data) {
|
||||||
assert.throws(() => accessor.getProperty(pathArray));
|
assert.throws(() => accessor.getProperty(pathArray), {message});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,20 +123,20 @@ function testSetProperty2() {
|
|||||||
|
|
||||||
const testValue = {};
|
const testValue = {};
|
||||||
const data = [
|
const data = [
|
||||||
[0],
|
[[0], 'Invalid path: [0]'],
|
||||||
['0', 'invalid'],
|
[['0', 'invalid'], 'Invalid path: ["0"].invalid'],
|
||||||
['value1', 'value2', 0],
|
[['value1', 'value2', 0], 'Invalid path: value1.value2[0]'],
|
||||||
['value1', 'value3', 'invalid'],
|
[['value1', 'value3', 'invalid'], 'Invalid path: value1.value3.invalid'],
|
||||||
['value1', 'value4', 'invalid'],
|
[['value1', 'value4', 'invalid'], 'Invalid path: value1.value4.invalid'],
|
||||||
['value1', 'value4', 0],
|
[['value1', 'value4', 0], 'Invalid path: value1.value4[0]'],
|
||||||
['value5', 1, 'invalid'],
|
[['value5', 1, 'invalid'], 'Invalid path: value5[1].invalid'],
|
||||||
['value5', 2, 'invalid'],
|
[['value5', 2, 'invalid'], 'Invalid path: value5[2].invalid'],
|
||||||
['value5', 2, 0],
|
[['value5', 2, 0], 'Invalid path: value5[2][0]'],
|
||||||
['value5', 2.5]
|
[['value5', 2.5], 'Invalid index']
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const pathArray of data) {
|
for (const [pathArray, message] of data) {
|
||||||
assert.throws(() => accessor.setProperty(pathArray, testValue));
|
assert.throws(() => accessor.setProperty(pathArray, testValue), {message});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,12 +163,12 @@ function testGetPathString1() {
|
|||||||
|
|
||||||
function testGetPathString2() {
|
function testGetPathString2() {
|
||||||
const data = [
|
const data = [
|
||||||
[1.5],
|
[[1.5], 'Invalid index'],
|
||||||
[null]
|
[[null], 'Invalid type: object']
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const pathArray of data) {
|
for (const [pathArray, message] of data) {
|
||||||
assert.throws(() => ObjectPropertyAccessor.getPathString(pathArray));
|
assert.throws(() => ObjectPropertyAccessor.getPathString(pathArray), {message});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user