Tuesday 30 April 2019

How do i set authentication token to chai-http

I have create some test cases with ran successfully however cases that need token fails.this is the error messagePOST /api/v1/auth/signinshould sign registered user in:Uncaught TypeError: Cannot read property 'token' of undefinedat token (API\src\tests/users.test.js:124:54)at Test.Request.callback (node_modules\superagent\lib\node\index.js:716:12)at IncomingMessage.parser (node_modules\superagent\lib\node\index.js:916:18)at endReadableNT (_stream_readable.js:1094:12)at process._tickCallback (internal/process/next_tick.js:63:19)this is my codeimport chai from 'chai';import chaiHttp from 'chai-http';import app from '../../server';chai.should();chai.use(chaiHttp);describe('POST /api/v1/auth/signin', () => {it('should sign registered user in', (done) => {const user = {email: 'mail@mail.com',password: 'password',};chai.request(app).post(' /api/v1/auth/signin').send(user).end((loginReq, loginRes) => {const token = \Bearer ${loginRes.body.user.token}`; chai .request(app) .post('/api/v1/auth/signin') .set('authorization', token) .end((err, res) => { res.should.have.status(200); res.body.should.be.a('object'); done(); }); }); }); });`

Submitted April 30, 2019 at 05:49PM by PearllyO

No comments:

Post a Comment