Skip to content

Commit

Permalink
test that there is no data change on error
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrasinskis committed Sep 3, 2024
1 parent 7d0f053 commit 731f58c
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions frontend/src/tests/lib/pages/IcrcWallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,24 @@ describe("IcrcWallet", () => {

it("should stay on the same page when removal is unsuccessful", async () => {
vi.spyOn(console, "error").mockReturnValue();
vi.spyOn(importedTokensApi, "setImportedTokens").mockRejectedValue(
new Error()
const spyOnSetImportedTokens = vi
.spyOn(importedTokensApi, "setImportedTokens")
.mockRejectedValue(new Error());
const spyOnGetImportedTokens = vi.spyOn(
importedTokensApi,
"getImportedTokens"
);
vi.spyOn(importedTokensApi, "getImportedTokens").mockResolvedValue({
imported_tokens: [],
});

expect(get(importedTokensStore).importedTokens).toEqual([
{
ledgerCanisterId,
indexCanisterId: undefined,
},
{
ledgerCanisterId: ledgerCanisterId2,
indexCanisterId: undefined,
},
]);

const po = await renderWallet({});
const morePopoverPo = po.getWalletMorePopoverPo();
Expand All @@ -624,8 +636,21 @@ describe("IcrcWallet", () => {
await runResolvedPromises();
await confirmationPo.clickYes();
await runResolvedPromises();
expect(spyOnSetImportedTokens).toBeCalledTimes(1);
// should stay on wallet page
expect(get(pageStore).path).toEqual(AppPath.Wallet);
// without data change
expect(spyOnGetImportedTokens).toBeCalledTimes(0);
expect(get(importedTokensStore).importedTokens).toEqual([
{
ledgerCanisterId,
indexCanisterId: undefined,
},
{
ledgerCanisterId: ledgerCanisterId2,
indexCanisterId: undefined,
},
]);
});
});
});

0 comments on commit 731f58c

Please sign in to comment.