diff --git a/src/JsonDB.ts b/src/JsonDB.ts index fe91df3a..c3788d6d 100644 --- a/src/JsonDB.ts +++ b/src/JsonDB.ts @@ -442,9 +442,6 @@ export class JsonDB { const pathValue = pathObject[pathKey] try { const pathIndex = await this.getIndex(normalPath.join(""), pathValue) - if(pathIndex === -1){ - throw new DataError(`DataPath: ${normalPath.join("")}/${pathValue} not found.`, 13) - } normalPath.push(`[${pathIndex}]`) } catch (error) { throw new DataError(`DataPath: ${normalPath.join("")}/${pathValue} not found.`, 13, error) diff --git a/test/JsonDB.test.ts b/test/JsonDB.test.ts index aa1a8cf9..6d80287c 100644 --- a/test/JsonDB.test.ts +++ b/test/JsonDB.test.ts @@ -97,7 +97,7 @@ describe('JsonDB', () => { }) describe('toPath()', () => { - test('should throw path error when path not found', () => { + test('should throw path error when not found item',() => { db.getData = jest.fn(async () => ({ a: [ { @@ -105,10 +105,11 @@ describe('JsonDB', () => { } ] })) + expect(async () => { - await db.toPath('/a/2') + await db.toPath('/a/1') }).rejects.toThrow( - 'DataPath: /a/2 not found.' + 'DataPath: /a/1 not found.' ) }) })