aboutsummaryrefslogtreecommitdiff
path: root/test/test-object-property-accessor.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-13 18:17:40 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-14 13:51:06 -0400
commit7e1e7d59cd8f076b8ee07c354ed11724364cc9fa (patch)
tree083fde7eb9c29cebe784313250ca2f5115ac0e4a /test/test-object-property-accessor.js
parent174a942e07b80b419729dbc9f8832e0b5b2f9b36 (diff)
Add error message checking
Diffstat (limited to 'test/test-object-property-accessor.js')
-rw-r--r--test/test-object-property-accessor.js72
1 files changed, 36 insertions, 36 deletions
diff --git a/test/test-object-property-accessor.js b/test/test-object-property-accessor.js
index 69e5dbdb..fb912b21 100644
--- a/test/test-object-property-accessor.js
+++ b/test/test-object-property-accessor.js
@@ -68,28 +68,28 @@ function testGetProperty2() {
const accessor = new ObjectPropertyAccessor(object);
const data = [
- [0],
- ['0', 'invalid'],
- ['invalid'],
- ['value1', 'invalid'],
- ['value1', 'value2', 'invalid'],
- ['value1', 'value2', 0],
- ['value1', 'value3', 'invalid'],
- ['value1', 'value3', 0],
- ['value1', 'value4', 'invalid'],
- ['value1', 'value4', 0],
- ['value5', 'length'],
- ['value5', 0, 'invalid'],
- ['value5', 0, 0],
- ['value5', 1, 'invalid'],
- ['value5', 1, 0],
- ['value5', 2, 'invalid'],
- ['value5', 2, 0],
- ['value5', 2.5]
+ [[0], 'Invalid path: [0]'],
+ [['0', 'invalid'], 'Invalid path: ["0"].invalid'],
+ [['invalid'], 'Invalid path: invalid'],
+ [['value1', 'invalid'], 'Invalid path: value1.invalid'],
+ [['value1', 'value2', 'invalid'], 'Invalid path: value1.value2.invalid'],
+ [['value1', 'value2', 0], 'Invalid path: value1.value2[0]'],
+ [['value1', 'value3', 'invalid'], 'Invalid path: value1.value3.invalid'],
+ [['value1', 'value3', 0], 'Invalid path: value1.value3[0]'],
+ [['value1', 'value4', 'invalid'], 'Invalid path: value1.value4.invalid'],
+ [['value1', 'value4', 0], 'Invalid path: value1.value4[0]'],
+ [['value5', 'length'], 'Invalid path: value5.length'],
+ [['value5', 0, 'invalid'], 'Invalid path: value5[0].invalid'],
+ [['value5', 0, 0], 'Invalid path: value5[0][0]'],
+ [['value5', 1, 'invalid'], 'Invalid path: value5[1].invalid'],
+ [['value5', 1, 0], 'Invalid path: value5[1][0]'],
+ [['value5', 2, 'invalid'], 'Invalid path: value5[2].invalid'],
+ [['value5', 2, 0], 'Invalid path: value5[2][0]'],
+ [['value5', 2.5], 'Invalid index']
];
- for (const pathArray of data) {
- assert.throws(() => accessor.getProperty(pathArray));
+ for (const [pathArray, message] of data) {
+ assert.throws(() => accessor.getProperty(pathArray), {message});
}
}
@@ -123,20 +123,20 @@ function testSetProperty2() {
const testValue = {};
const data = [
- [0],
- ['0', 'invalid'],
- ['value1', 'value2', 0],
- ['value1', 'value3', 'invalid'],
- ['value1', 'value4', 'invalid'],
- ['value1', 'value4', 0],
- ['value5', 1, 'invalid'],
- ['value5', 2, 'invalid'],
- ['value5', 2, 0],
- ['value5', 2.5]
+ [[0], 'Invalid path: [0]'],
+ [['0', 'invalid'], 'Invalid path: ["0"].invalid'],
+ [['value1', 'value2', 0], 'Invalid path: value1.value2[0]'],
+ [['value1', 'value3', 'invalid'], 'Invalid path: value1.value3.invalid'],
+ [['value1', 'value4', 'invalid'], 'Invalid path: value1.value4.invalid'],
+ [['value1', 'value4', 0], 'Invalid path: value1.value4[0]'],
+ [['value5', 1, 'invalid'], 'Invalid path: value5[1].invalid'],
+ [['value5', 2, 'invalid'], 'Invalid path: value5[2].invalid'],
+ [['value5', 2, 0], 'Invalid path: value5[2][0]'],
+ [['value5', 2.5], 'Invalid index']
];
- for (const pathArray of data) {
- assert.throws(() => accessor.setProperty(pathArray, testValue));
+ for (const [pathArray, message] of data) {
+ assert.throws(() => accessor.setProperty(pathArray, testValue), {message});
}
}
@@ -163,12 +163,12 @@ function testGetPathString1() {
function testGetPathString2() {
const data = [
- [1.5],
- [null]
+ [[1.5], 'Invalid index'],
+ [[null], 'Invalid type: object']
];
- for (const pathArray of data) {
- assert.throws(() => ObjectPropertyAccessor.getPathString(pathArray));
+ for (const [pathArray, message] of data) {
+ assert.throws(() => ObjectPropertyAccessor.getPathString(pathArray), {message});
}
}