Wednesday, 3 May 2017

How to test Rest API by running Mocha Test via an html file?

Hello Experts: Need your help.

I user supertest to test rest api using mocha.

When running the mocha test from the node terminal it works. I can add the module using the below statement.

const request = require('supertest');

Question is: i want to run it from browser - say, using a testrunner.html. I am unable to make it work.

....i tried adding this to the runner.html
<script src="./test/node_modules/supertest/index.js"></script>

...and in test.js, added the following
var server = supertest.agent(theendpoint);

**Error is**
ReferenceError: supertest is not defined

Please help. Is there is someway to test the REST APIs when running the mocha tests via an html file? Many thanks in advance...



via Bipo K

No comments:

Post a Comment