mocha.js

Configuration for Debugging Mocha Unit Tests in Vue.js with VSCode

一个人想着一个人 提交于 2021-01-29 10:55:39
问题 I am currently facing some problems getting my tests to debug properly with VSCode in Vue.js (I am using Mocha and Webpack) The first configuration I found which got me a bit closer was this one. Configuration in .vscode/launch.json { "type": "node", "request": "launch", "name": "Unit Tests", "program": "${workspaceFolder}/node_modules/@vue/cli-service/bin/vue-cli-service.js", "args": [ "test:unit" ], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" } Now this solution

can not access global 'allure' object using mocha-allure

这一生的挚爱 提交于 2021-01-28 08:41:25
问题 According to mocha-allure docs, if you want to use allure outside of before/beforeEach you should import the reporter directly. Or once added mocha-allure-reporter will create global allure object with the following API: https://github.com/allure-framework/allure-mocha https://github.com/allure-examples/mocha-allure-example/blob/master/test/simple.spec.js However I followed the example in the docs, but i get Cannot find name 'allure'. , when using it in either the before or afterEach. test

mocha “describe” is not defined

人走茶凉 提交于 2021-01-28 08:21:01
问题 I read all the related mocha "describe" is not defined posts but none of them seem to be suitable for my situation. I use meteor and installed the "mocha": "^3.5.0" package by npm I have created a /test folder in my meteor root directory. and a sample test mochatest.js var assert = require("assert"); // node.js core module describe('Array', function(){ describe('#indexOf()', function(){ it('should return -1 when the value is not present', function(){ assert.equal(-1, [1,2,3].indexOf(4)); // 4

VSCode: Tests won't proceed after using executeCommand to open a sample project

蹲街弑〆低调 提交于 2021-01-28 05:26:56
问题 I'm trying to add some unit tests to a Visual Studio Code extension I'm developing. I've followed the recipe for setting up extension testing described here: https://code.visualstudio.com/api/working-with-extensions/testing-extension This recipe, however, doesn't show anything useful being done to actually test an extension, just the skeleton for getting set up to do so. For the testing I want to do, one of the first things I want to do is open a sample project . And that's where I get stuck.

mocha share variables between files

孤街醉人 提交于 2021-01-27 23:10:32
问题 I am trying to wire the objects between 2 mocha test files. Here is my test1.js file which should export a variable once all the test cases are executed. var assert = require('assert'); var newUser = { email: "test@ex.com", name: "test@ex.com", password: "test@ex.com", confirmPassword: "test@ex.com" } var studentAcademicData = { marks: {}, activities: {} } var studentInterests = [] var testSummary = {}, loggedInUser = {}, avaialbleAssessment = {}, test = {}, interests = {}; var

Extending SuperTest

对着背影说爱祢 提交于 2021-01-27 13:37:31
问题 I like to use SuperTest to work with my auth system like this: const request = require('./valid_access_token')(require('supertest')); request(app) .get('/v1/bots') .valid_token() .expect('Content-Type', /json/) ... valid_token() would insert a valid access-token module.exports = function (Request) { const Token = require('../../../app/v1/models/loader')('token'); const UserFactory = require('../fixtures/user'); Request.prototype.valid_token = function() { return UserFactory.createAsync('user'

How do I make Nock and Mocha play well together?

◇◆丶佛笑我妖孽 提交于 2021-01-27 12:27:18
问题 I am trying to use nock to intercept/mock some HTTP traffic in my application for testing purposes. Our app authenticates to another one of our sites, and I need nock to imitate an HTTP 200 (with JSON data) and an HTTP 401 (with no data) to test behaviors when the user is or isn't logged in there (respectively). I have two tests which both work correctly when run alone, but if I run the entire test suite, one of them always fails. I realize that nock is shared state because it modifies how

[node][mocha]Global variables not accessible when testing with mocha

柔情痞子 提交于 2021-01-27 10:01:09
问题 I'm trying to create a unit test for express node application. I want the configuration used for the test to be different than the one used in production, so I implemented the following. In my index.js , I load the configuration into the global variable like this: global.env = {}; global.env.config = require('./config/config'); // Create the server ... server.listen(3000); module.exports = server; In some other controller myController.js , I access the global variable like this var Config =

How to mock npm module with sinon/mocha

不想你离开。 提交于 2021-01-27 06:42:00
问题 I'm trying to test a function that calls the module cors . I want to test that cors would be called. For that, I'd have to stub/mock it. Here is the function cors.js const cors = require("cors"); const setCors = () => cors({origin: 'http//localhost:3000'}); module.exports = { setCors } My idea of testing such function would be something like cors.test.js describe("setCors", () => { it("should call cors", () => { sinon.stub(cors) setCors(); expect(cors).to.have.been.calledOnce; }); }); Any

How to mock npm module with sinon/mocha

这一生的挚爱 提交于 2021-01-27 06:41:02
问题 I'm trying to test a function that calls the module cors . I want to test that cors would be called. For that, I'd have to stub/mock it. Here is the function cors.js const cors = require("cors"); const setCors = () => cors({origin: 'http//localhost:3000'}); module.exports = { setCors } My idea of testing such function would be something like cors.test.js describe("setCors", () => { it("should call cors", () => { sinon.stub(cors) setCors(); expect(cors).to.have.been.calledOnce; }); }); Any