title: node.js Mocha : how to reuse a variable defined in a local setup before() hook?
body: <p><strong>UPDATED</strong> </p>
  
  <p>In my ('resource' test , I create a new User</p>
  
  <pre><code>/**
   * root level hooks
   */
  before((done) =&gt; {
    const newUser = new User({
      username: 'johndoe',
      password: 'jdpwd',
      email: 'johndoe@example.com',
      mobileNumber: 123456789
    });
    newUser.save((err) =&gt; {
      // console.log('error: ', err);
      done();
    });
  });
  </code></pre>
  
  <p>I would like to reuse the user id in my test :</p>
  
  <pre><code>describe('## Resource APIs', () =&gt; {
  const user = User.findOne({ username: 'johndoe' });
  console.log('got user: ', user.id);
    let resource = {
      name: 'RS123',
      description: 'RS123Description',
      owner: user._id,   &lt;= should be the id of the newUser
      private: true
    };
    describe('# POST /api/v1/resources', () =&gt; {
      it('should create a new resource', (done) =&gt; {
        request(app)
          .post('/api/v1/resources')
          .send(resource)
          .expect(httpStatus.OK)
          .then((res) =&gt; {
            expect(res.body.name).to.equal(resource.name);
            expect(res.body.description).to.equal(resource.description);
            resource = res.body;
            done();
          })
          .catch(done);
      });
    });
     ...
  });
  </code></pre>
  
  <p>but user is undefined.. </p>
  
  <p>how can I change it ?
  thanks for feedback</p>