regex - Mocha Supertest json response body pattern matching issue -
when make api call want inspect returned json results. can see body , static data being checked properly, wherever use regular expression things broken. here example of test:
describe('get user', function() { it('should return 204 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(); }); }); }); });
here image of output:
any ideas on using regular expression pattern matching json body response?
i asked question in understanding of framework. else stumbles on this, recommend using chai assertion. helped use regular expression pattern matching in cleaner way.
here example:
res.body.should.have.property('id').and.to.be.a('number').and.to.match(/^[1-9]\d{8,}$/);
Comments
Post a Comment