Skip to content

Commit

Permalink
Merge pull request #1841 from demergent-labs/jest_i_examples
Browse files Browse the repository at this point in the history
Update examples that start with "i" to use jest
  • Loading branch information
lastmjs authored Jun 18, 2024
2 parents 80f6cf5 + bcefded commit 2c3097f
Show file tree
Hide file tree
Showing 40 changed files with 55,004 additions and 16,132 deletions.
32 changes: 12 additions & 20 deletions examples/ckbtc/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,22 @@ export function getTests(): Test {

const updateBalanceResult = await config.canister.updateBalance();

if ('Err' in updateBalanceResult) {
throw new Error(Object.keys(updateBalanceResult.Err)[0]);
}

expect(true).toBe(true);
expect(updateBalanceResult).not.toHaveProperty('Err');
});

it('fails to update balance for second identity without new utxos', async () => {
const config = db[1];

const updateBalanceResult = await config.canister.updateBalance();

if ('Ok' in updateBalanceResult) {
throw new Error(
`Expected principal ${config.caller} to not have new UTXOs`
);
}
const errorType = Object.keys(updateBalanceResult.Err)[0];

expect(errorType).toBe('NoNewUtxos');
expect(updateBalanceResult).toStrictEqual({
Err: {
NoNewUtxos: {
required_confirmations: 1,
current_confirmations: []
}
}
});
});

it('gets balance for first identity', async () => {
Expand All @@ -96,17 +92,13 @@ export function getTests(): Test {
it('transfers 1_000_000_000n from first canister to second canister', async () => {
const config = db[0];

const tranferResult = await config.canister.transfer(
const transferResult = await config.canister.transfer(
db[1].caller,
1_000_000_000n
);

if ('Err' in tranferResult) {
throw new Error(Object.keys(tranferResult.Err)[0]);
}

const transferIndex = tranferResult.Ok;
expect(transferIndex).toBe(1n);
expect(transferResult).not.toHaveProperty('Err');
expect(transferResult).toStrictEqual({ Ok: 1n });
});

it('gets balance for first identity after transfer', async () => {
Expand Down
4 changes: 2 additions & 2 deletions examples/ethers_base/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getTests(canisterId: string): Test {

callerAddress = responseText;

expect(responseText).toMatch('0x');
expect(responseText).toMatch(/^0x/);
expect(responseText).toHaveLength(42);
});

Expand All @@ -34,7 +34,7 @@ export function getTests(canisterId: string): Test {

canisterAddress = responseText;

expect(responseText).toMatch('0x');
expect(responseText).toMatch(/^0x/);
expect(responseText).toHaveLength(42);
expect(responseText).not.toBe(callerAddress);
});
Expand Down
10 changes: 10 additions & 0 deletions examples/ic_api/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.js$': 'ts-jest'
},
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed
};
Loading

0 comments on commit 2c3097f

Please sign in to comment.