title: Mocha test of REST API
body: <p>I'm testing a REST API, where the data just comes from a JSON file in the project.</p>
  
  <p>When i test the post method, some of my other test now fails. Because there now is one more object in the array.</p>
  
  <p>What would be the best approach to setup in a before/beforeEach, so the array is the same state in every other test that runs.</p>
  
  <p>Thanks. </p>
  
  <pre><code>  describe("GET-methods: ", function () {
  
      it("should provide 9 users:", function (done) {
          request({method: 'GET', url: URL, json: true}, function (err, res, body) {
              if(err) throw err;
              body.should.have.length(9);
              done();
          });
      });
  
      it("should find password given email", function (done) {
          request({method: 'GET', url: URL+"/lorem@ipsum.com", json: true}, function (err, res, body) {
              if(err) throw err;
              body.password.should.equal("8F1E-3218-AC06800CA5AC");
              done();
          });
      });
  });
  
   describe("POST-methods: ", function () {
  
      var newUser = {email: "a@b.dk", password: "secret"};
      var options = {method: "POST",url : URL, body : newUser,json: true};
      before(function(done){
          request(options,function(err, status, body){
              if(err) throw err;
              done();
          });
      });
  
     it("should find the new user", function (done) {
          request({method: 'GET', uri: URL+"/a@b.dk", json: true}, function (err, res, body) {
              if(err) throw err;
              body.password.should.equal("secret");
              done();
          });
      });
  });
  </code></pre>