mocha

How do I setup code coverage on my Express based API?

折月煮酒 提交于 2020-07-18 03:44:41
问题 I've been at this problem for a while and I cannot make the existing solutions work for me. I have a Node.js API written in Express.js. I have been writing tests for the API using Mocha, Chai, and Supertest. These test are mostly integration tests. One test may look like: it('should fail to register a new user without the proper information', function(done) { api.post('/user') .send({}) .expect(400) .expect('Content-Type', /json/) .end(function(err, res) { should.exist(res.body); should.exist

How do I setup code coverage on my Express based API?

只愿长相守 提交于 2020-07-18 03:44:09
问题 I've been at this problem for a while and I cannot make the existing solutions work for me. I have a Node.js API written in Express.js. I have been writing tests for the API using Mocha, Chai, and Supertest. These test are mostly integration tests. One test may look like: it('should fail to register a new user without the proper information', function(done) { api.post('/user') .send({}) .expect(400) .expect('Content-Type', /json/) .end(function(err, res) { should.exist(res.body); should.exist

How to stub express middleware using sinon in typescript?

强颜欢笑 提交于 2020-07-10 10:27:35
问题 I'm trying to write an integration test for my express router using typescript, mocha, sinon and chai-http. This router uses a custom middleware that I wrote which checks for JWT in the header. Ideally, I want to stub my authMiddleware so that I can control its behaviour without actually providing valid/invalid JWT for every test case. When I try to stub authMiddleware in my tests, I realised that express app uses the actual implementation of authMiddleware rather than mocked one. I've tried

cy.request doesn't allowing me to go to next UI test cases

余生长醉 提交于 2020-07-10 07:49:09
问题 Trying to integrate both UI & API test cases Created two files: API test --> DO Login and writing token & saving it to fixture file Spec test -->Do REAL Login by using username and password and once test case pass then in next test first get the response by using cy.request using token which saved by step1. Based on response keys search the data in search bar API Test File: it("Login Request API",function(){ cy.request({ method:"POST", url: POST URL, headers:{ "content-type" : "application

Cypress - Report not generating while running tests through cypress test runner

≯℡__Kan透↙ 提交于 2020-07-10 07:00:10
问题 When I hit the command npx cypress run , my test run and videos are recorded and also a mochawesome report is generated and saved. However when I run the test through cypress test runner, using the command cypress open and then selecting a spec run, the tests run , but the videos and the report are not generated. How can I make video/screenshot recording along with report generation using Cypress Test Runner? 来源: https://stackoverflow.com/questions/62628788/cypress-report-not-generating-while

Setup variable in mocha suite before each test?

眉间皱痕 提交于 2020-07-06 13:00:10
问题 I would like to setup some variables first, before executing the test, and I found this solution, Running Mocha setup before each suite rather than before each test But, I dont know how can I pass the variable into my callback, they way I did I will get undefined makeSuite('hello', (context) => { it('should return', () => { assert.strictEqual(1, 1) }) }) makeSuite('world', (context) => { it('should return', () => { console.log(context) // undefined assert.strictEqual(1, 1) }) }) function

Testing a redirect to a new route with Cypress

邮差的信 提交于 2020-07-05 05:34:08
问题 I am using Cypress for testing my web application. This snippet currently works and will submit a new thing: describe('The Create Page', () => { it('successfully creates a thing', () => { cy.visit('/create') cy.get('input[name=description]').type('Hello World') cy.get('button#submit') .click() // After POST'ing this data via AJAX, the web app then // receives the id of the new thing that was just created // and redirects the user to /newthing/:id // How do I test that this redirection worked?

mongoose.connect(), first argument should be String, received undefined

核能气质少年 提交于 2020-07-05 01:42:58
问题 I am trying to set the test database for the testing purpose, but its not working. I am trying to connect to mongodb using mongoose, but finding problem in connection error shows: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' + ^ MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()`is a string. at new MongooseError (/media/abhigyan/ABHI/programming

mongoose.connect(), first argument should be String, received undefined

蓝咒 提交于 2020-07-05 01:37:06
问题 I am trying to set the test database for the testing purpose, but its not working. I am trying to connect to mongodb using mongoose, but finding problem in connection error shows: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' + ^ MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()`is a string. at new MongooseError (/media/abhigyan/ABHI/programming

mongoose.connect(), first argument should be String, received undefined

你。 提交于 2020-07-05 01:31:27
问题 I am trying to set the test database for the testing purpose, but its not working. I am trying to connect to mongodb using mongoose, but finding problem in connection error shows: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' + ^ MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()`is a string. at new MongooseError (/media/abhigyan/ABHI/programming