Run a test in Jest only if certain condition are met

Viewed 15

I want to run certain tests depending on certain conditions. If the condition is met then run, otherwise skip the test. I want to do that before being in the test (or maybe jest provide a function to cancel a test inside it? So that it doesn't throw an error)

You can see here what I have : enter image description here

The setup: I'm testing different crypto-wallet for a DEX, so I have a battery of tests that runs for all those wallets. By design, some features are on some wallets and others don't have them. Here I'm trying to sign a transaction running on an EVM chain different from Ethereum (AVAX here). This will not work on all wallets (normal) like ethwallet, but will for others. I want to test only those that I know support this feature.

My problem: wallet is initialized in beforeAll, and I don't have access to this object outside test() (the expected log is k2, k1 is out of scope and return gibberish). How can I access it then and know if I run the test or skip it? You can see that I tried to implement testif() but unfortunately not working because I have not the good value outside of test().

0 Answers
Related