当我进行 API 调用时,我想检查返回的 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": "qa_test+apitest@example.com",
"registered": /./,
"first_name": "",
"last_name": ""
})
.end(function(err, res) {
if (err) return done(err);
done();
});
});
});
});
这是输出的图像:
关于使用正则表达式进行模式匹配 json 正文响应的任何想法?