2017-11-30 9 views
0

を掲示されていない私のテストは、次のようになります。私のアプリではモカsupertestはデータ

const request = require('supertest-as-promised') 
const app = require('../app') 

describe("Basic Authentication with JWT",() => { 
    it('Should login properly', function() { 
    return request(app) 
     .post('/login') 
     .field('name', 'myname') 
     .field('password', 'password') 
     .expect(200) 
    }); 
}) 

、私が持っている:私は正常にアプリを実行すると

app.post("/login", (req, res) => { 
    console.log(req.body) 

、それは適切な情報を取得します。テストを実行すると、{}

と表示されます。

答えて

2

ようなものを試してみてください:

describe("Basic Authentication with JWT",() => { 
     it('Should login properly', function() { 
     request(app) 
       .post('/login') 
       .send({ 
        name: "test_name", 
        password: "test_password" 
       }) 
       .then((res) => { 
        res.statusCode.should.eql(200); 
        done(); 
       }) 
       .catch(done) 
     }); 
    })