Skip to content

Commit

Permalink
fix(tests): change control flow pattern to .catch instead of trycatch
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Feb 15, 2024
1 parent 590dea6 commit 883de51
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions tests/arns-remote-cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ArIO } from '../src/common/ar-io.js';
import { ArNSRemoteCache } from '../src/common/caches/arns-remote-cache.js';
import { FailedRequestError } from '../src/common/error.js';

describe('ArIO Client', () => {
const remoteCacheProvider = new ArNSRemoteCache({});
Expand All @@ -21,31 +22,21 @@ describe('ArIO Client', () => {
});

it('should throw on bad contract id', async () => {
let result;
try {
const contractTxId = ''.padEnd(42, 'a');
result = await arioClient
.getContractState({ contractTxId })
.catch((e) => e);
} catch (error) {
result = error;
}
const contractTxId = ''.padEnd(42, 'a');
const result = (await arioClient
.getContractState({ contractTxId })
.catch((e) => e)) as any;

expect(result).toBeInstanceOf(Error);
});

it('should throw 404 on non existent contract', async () => {
let result;
try {
const contractTxId = ''.padEnd(43, 'a');
result = await arioClient
.getContractState({ contractTxId })
.catch((e) => e);
} catch (error) {
result = error;
}
const contractTxId = ''.padEnd(43, 'a');
const result = (await arioClient
.getContractState({ contractTxId })
.catch((e: any) => e)) as any;

expect(result).toBeInstanceOf(Error);
expect(result.message).toMatch(/404/);
expect(result).toBeInstanceOf(FailedRequestError);
expect(result?.message).toMatch(/404/);
});
});

0 comments on commit 883de51

Please sign in to comment.