Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

65
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.

7 months 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 = '';
  }
});
7 months 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 job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.