Created
          November 14, 2013 07:03 
        
      - 
      
- 
        Save Madhuka/7462637 to your computer and use it in GitHub Desktop. 
    mocha test file for REST api
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var request = require('superagent'); | |
| var expect = require('expect.js'); | |
| var express = require('express'); | |
| // 'express' is used in bodyParser if needed | |
| describe('Suite one - #REST API test', function() { | |
| var name = 'jhon'; | |
| it('- GET is testing', function(done) { | |
| request.get('http://localhost:9763/jaggeryApp/').end(function(res) { | |
| expect(res).to.exist | |
| expect(res.status).to.equal(200); | |
| expect(res.text).to.contain('testing API'); | |
| expect(res.type).to.contain('text'); | |
| expect(res.header.hasOwnProperty('customheader')).to.equal(true); | |
| //console.log(res); //can be used log in mocha | |
| done(); | |
| }); | |
| }); | |
| it('- POST is testing', function(done) { | |
| request.post('http://localhost:9763/jaggeryApp/?name=' + name).send().end(function(e, res) { | |
| //console.log(res.text) | |
| expect(e).to.eql(null) | |
| expect(res.text).to.contain(name); | |
| done() | |
| }) | |
| }) | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment