Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples that start with "i" to use jest #1841

Merged
merged 11 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions examples/ckbtc/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,17 @@ 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).toEqual(
expect.objectContaining({ Err: 'NoNewUtxos' })
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
);
});

it('gets balance for first identity', async () => {
Expand All @@ -96,17 +87,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
Loading