APIコールを行うと、返されたJSONの結果を調べたいと思います。私は身体を見ることができ、いくつかの静的データは正しくチェックされていますが、私が正規表現を使用するところはどこも壊れています。ここに私のテストの例です:Mocha Supertest jsonレスポンスボディパターンマッチングの問題
JSON本体の応答パターンマッチングのための正規表現を使用して上の任意のアイデア:
describe('get user', function() {
it('should return 204 with expected JSON', function(done) {
oauth.passwordToken({
'username': config.username,
'password': config.password,
'client_id': config.client_id,
'client_secret': config.client_secret,
'grant_type': 'password'
}, function(body) {
request(config.api_endpoint)
.get('/users/me')
.set('authorization', 'Bearer ' + body.access_token)
.expect(200)
.expect({
"id": /\d{10}/,
"email": "[email protected]",
"registered": /./,
"first_name": "",
"last_name": ""
})
.end(function(err, res) {
if (err) return done(err);
done();
});
});
});
});
ここでは、出力のイメージがありますか?
は、なぜあなたがしたいフィールドをつかむいない問題ではないフィールドを無視し使用します。それはあなたが正規表現で説明したものを処理することができますコールバック( 'var id = req.body.id')をチェックインし、アサーションライブラリで正規表現チェックを実行しますか? –
フィールドあたりの検査も読みやすくなります。 –