You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Errors from assert() function are not helpful in stack trace when testing with jest
asyncgetOne<T>(spec: QuerySpecification<T>): Promise<T>{constresults=awaitthis.persistenceManager.query(spec);assert(results.length===1,`Expected exactly one result`);returnresults[0];}
In tests doesn't say what happened
FAIL libs/api/db/src/lib/user/user.repository.spec.ts
● UserRepository › .update() › should update user
assert(received)
Expected value to be equal to:
true
Received:
false
Message:
Expected exactly one result
71 | const data = await userFixture.createFakeUser();
72 | const name = 'new name'> 73 | const updated = await userRepository.update(data.rid, {name});| ^
74 |
75 | const res: UserEntity = {
76 | rid: expect.any(String),
at FinderOperations.getOne (../../../node_modules/@liberation-data/src/manager/FinderOperations.ts:11:9)
at TransactionalPersistenceManager.getOne (../../../node_modules/@liberation-data/src/manager/TransactionalPersistenceManager.ts:23:16)
at runInTransaction (../../../node_modules/@liberation-data/src/transaction/Transactional.ts:39:24)
at src/lib/user/user.repository.spec.ts:73:23
We should always use custom errors like we do here:
asyncmaybeGetOne<T>(spec: QuerySpecification<T>): Promise<T|undefined>{constresults=awaitthis.persistenceManager.query(spec);if(results.length===0){returnundefined;}elseif(results.length===1){returnresults[0];}else{thrownewDrivineError(`Expected one result, received ${results.length}.`);}}
The text was updated successfully, but these errors were encountered:
Errors from assert() function are not helpful in stack trace when testing with jest
In tests doesn't say what happened
We should always use custom errors like we do here:
The text was updated successfully, but these errors were encountered: