Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
Is there a way to define variables usable in all subtests in node tap?

I was wondering if there's a way to declare a variable before all the subtests in node tap js in order to use it in each one of them. Something like this:

      tap.test('...', async (t) => {
         
        t.before(async () => {
           const myVariable = ...
        }

        t.test('SubTest 1', async (t) => {
           await someMethod(myVariable)
        }

        t.test('SubTest 2', async (t) => {
           await someMethod(myVariable)
        }
      }  

It can be achieved another way, the idea is that I'd like to initialize some variables that I'll be using through all the subtests.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to move the variable declaration where the others can read it.

tap.test('...', async (t) => {
  let myVariable;
  t.before(async () => {
    myVariable = '';
  }
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!