Skip to content

Commit

Permalink
fix: flaky test BTC Account - Overview has balance (#28181)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
Anti-pattern where we assert the balance BTC balance is 1BTC using
getText. We should rather find the element by the expected balance to
avoid race conditions


[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28181?quickstart=1)

## **Related issues**

Fixes: #28182

## **Manual testing steps**

1. Check ci

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
seaona authored Oct 30, 2024
1 parent 5bb3885 commit 5227d6f
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions test/e2e/flask/btc/btc-account-overview.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { strict as assert } from 'assert';
import { Suite } from 'mocha';
import { DEFAULT_BTC_BALANCE } from '../../constants';
import { withBtcAccountSnap } from './common-btc';
Expand Down Expand Up @@ -46,17 +45,19 @@ describe('BTC Account - Overview', function (this: Suite) {
await withBtcAccountSnap(
{ title: this.test?.fullTitle() },
async (driver) => {
// Wait for the balance to load up
await driver.delay(2000);

const balanceElement = await driver.findElement(
'.coin-overview__balance',
);
const balanceText = await balanceElement.getText();
await driver.waitForSelector({
testId: 'account-value-and-suffix',
text: `${DEFAULT_BTC_BALANCE}`,
});
await driver.waitForSelector({
css: '.currency-display-component__suffix',
text: 'BTC',
});

const [balance, unit] = balanceText.split('\n');
assert(Number(balance) === DEFAULT_BTC_BALANCE);
assert(unit === 'BTC');
await driver.waitForSelector({
tag: 'p',
text: `${DEFAULT_BTC_BALANCE} BTC`,
});
},
);
});
Expand Down

0 comments on commit 5227d6f

Please sign in to comment.