Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 24 17:07
    nicojs synchronize #4234
  • Apr 24 16:55
    juergba unlabeled #4251
  • Apr 24 15:47
    Daniel0113 edited #4219
  • Apr 24 15:45
    Daniel0113 edited #4219
  • Apr 24 15:11
    Daniel0113 synchronize #4219
  • Apr 24 14:01
    juergba labeled #4227
  • Apr 24 14:01
    juergba unlabeled #4227
  • Apr 24 14:01
    juergba unlabeled #4227
  • Apr 24 13:58
    juergba edited #4251
  • Apr 24 13:33
    juergba labeled #4251
  • Apr 24 12:52
    juergba milestoned #4251
  • Apr 24 12:52
    juergba labeled #4251
  • Apr 24 12:52
    juergba labeled #4251
  • Apr 24 12:52
    juergba labeled #4251
  • Apr 24 12:51
    juergba assigned #4251
  • Apr 24 12:51
    juergba review_requested #4251
  • Apr 24 12:51
    juergba opened #4251
  • Apr 24 12:37

    juergba on karma

    type check before calling retri… (compare)

  • Apr 24 06:26
    juergba labeled #4250
  • Apr 24 06:26
    juergba labeled #4250
Pedro🦖3
@pedroolimpiosi_twitter
my mocha is not working
im brazilian, so sorry if i dont write right
Miguel Marques
@munerf
Hello, I want to integrate mocha with a CI I have. I want to be able to implement a service that receives calls and runs tests: "run test FOO". I was able to make it work, but after running mocha.run for the first time, if I call it again the test fails. Do I need to reset the Mocha object or something?
Blake Niemyjski
@niemyjski
Hey
I'm trying to get my vs code dev experience much better and I have some work todo.. I noticed something odd just now
"name": "Test", "request": "launch", "type": "pwa-node", "program": "${workspaceRoot}/node_modules/.bin/_mocha", "args": [ "--recursive", "${workspaceFolder}/src/**/*-spec.ts" ], "runtimeArgs": [ "--require", "ts-node/register" ],
is a launch config for vs code... recursive works and resolves all my tests at src folder and then up to 3 levels deep
to achieve the same thing on the command line I have to do mocha --require ts-node/register --recursive ./src/*-spec.ts ./src/**/*-spec.ts ./src/**/**/*-spec.ts
it's not working with the same wildcard and I don't get what I'm missing.....
Blake Niemyjski
@niemyjski
I don't think this applies mochajs/mocha#3348
wow, solved it... I needed to add quotes around the glob
Ali Kemal Tarlaci
@alitarlaaci1981
Hello everyone. I m new here..just signed up.
I am doing webautomation with mocha and java script...
I cant find enough source online to practice. can someone help me please? I would really really appreciate it. I have nener used mocha framework before and I am new to java script. thank you thank you and thank you
Full Stack Ruby on Rails Developer
@webdev778
hi
haha, I'll
Aaron Byrom
@aar9nk
Hey all, I'm going through my first time as a mocha user and on the site documentation:
The getting started guide has" assert.equal([1, 2, 3].indexOf(4), -1); " Now node is saying that deprecated and to use strictEqual instead. Was kind of confusing, how do I go about getting that changed or am I in the wrong here?
Ali Kemal Tarlaci
@alitarlaaci1981
hello
dhuang612
@dhuang612
@aar9nk yeah looks like assert.equal is deprecated according to nodejs.org.
try
assert.strictEqual([1,2,3].indexOf(4), -1)
vsosnin
@vsosnin

Greetings! first time poster here... I've just started using mocha/chai so very much a beginner but here's my question. If I use nested chai expects, how do I make mocha to show me the exact line on where the expect in the main body of my test has failed? Currently it's showing the line of the nested expect instead. For example:
Here's my custom assert class (my-custom-assert.js)

const expect = require('chai').expect;
class MyCustomAssert {
     static isJsonResponse(status, body = {}) {
          return (response) => {
               expect(response).to.have.property('statusCode', status);
               expect(response).to.have.nested.property('header.content-type').matches(/application\/json/);
               expect(response.body).shallowDeepEqual(body);
          };
     }
}

that I then use in my mocha test (my-mocha-test.js):

const { MyCustomAssert } = require('../../asserts');
const { expect } = require('chai');
describe('PUT to /resource/:resource_id', () => {
     describe('with valid resource_id', () => {
          it('should return 200 status code', async () => {
               await api.putResource(resource_id, {
                    ...,
               }).expect(MyCustomAssert.isJsonResponse(200));
          });
     });
});

So when my test fails, the stack trace points to the expect in my-custom-asset.js only:
at .../asserts/my-custom-assert.js:9:29
But how do I make Mocha/chai to show me the file and line number in my-mocha-test.js as well?

edgar-koster
@edgar-koster

Hey all. I'm trying to start mocha with a config file but it says no tests found. my config file is in config\tests\mocha.json and i start with mocha --config config\tests\mocha.json. I've confirmed the file is being read. My file content is

{
    "diff": true,
    "extension": [
        "ts"
    ],
    "package": "../../package.json",
    "slow": 75,
    "timeout": 2000,
    "ui": "bdd",
    "watch-files": [
        "../../tests/unit/**/*.spec.ts"
    ],
    "watch-ignore": [
        "../../node_modules"
    ]
}

Can someone helpout?

I also know that tests/unit/**/*.spec.ts works if I run that directly at the prompt. So either its getting to the directory or the watch-files option is wrong
Alex J Burke
@alexjeffburke
if you punch in that glob on the command line you're going to get shell expansion kick in - I think at minimum you need recursive: true in your config to deeply search your tests folder, but you probably also need to tell mocha to search that. You'd need less options if you move the tests into the standard test/.... path which is the default (you still need recursive)
Alex J Burke
@alexjeffburke
This message was deleted
Peter Müller
@Munter
@edgar-koster The property you are looking for is spec, which corresponds to the command line arguments
Denis Kurashko
@DJ-Glock
Hi all,
I would like to ask you if there is an ability to put process_id into each line of the mocha output?
Asked the same on the github:
mochajs/mocha#4509
Or is there any way to write log to different log files (for each process)?
Ignacio Montero
@IGMontero

Hey guys, got a pretty specific error but maybe somebody can help.
I'm using Mocha and Chai to test a node app, and im facing an issue that when a test fails, the complete test script stops and does not execute the other tests.
This is an example of the code:

describe('Subscriptions Routes', () => {
  before(function (done) {
    User.findById(testUserId).populate("_subscriptionsInfo").then(user => {
      testUser = user;
      done();
    });
  });


describe('METHOD getInfiniteSubscriptionPlanData', () => {
    it('Should return infinite subscription plan data from PayPal OR database', async () => {
      (async () => {
        try {
          const dbPlanData = await subscriptionServices.getInfinitePlanData();
          expect(dbPlanData).to.be.an('object');
          expect(dbPlanData.id).to.equal(PAYPAL_MONTHLY_SUBSCRIPTION_PLAN_ID);
          done();
        } catch (err) {
          done(err);
        }
      })();

    });
  });
});

When I run this script and any expect fails, it just stops the execution.

Thanks!

Peter Müller
@Munter
@IGMontero You are using the async callback form without any reason to. Here's a simplified version:
describe('Subscriptions Routes', () => {
    before(async function () {
        testUser = await User.findById(testUserId).populate("_subscriptionsInfo");
    });

    describe('METHOD getInfiniteSubscriptionPlanData', () => {
        it('Should return infinite subscription plan data from PayPal OR database', async () => {
            const dbPlanData = await subscriptionServices.getInfinitePlanData();
            expect(dbPlanData).to.be.an('object');
            expect(dbPlanData.id).to.equal(PAYPAL_MONTHLY_SUBSCRIPTION_PLAN_ID);
        });
    });
});
Ignacio Montero
@IGMontero
@Munter Hey, thanks for the response. I tried the code you sent me and the same is happening. The case fails and script stops and do not run the other cases. Here is the output:
  1) Should return infinite subscription plan data from PayPal OR database


  0 passing (4s)
  1 failing

  1) Subscriptions Routes
       METHOD getInfiniteSubscriptionPlanData
         Should return infinite subscription plan data from PayPal OR database:

      AssertionError: expected 'P-7K956295LM2452841L6362BA' to equal 'P-2F864278U36749846L4PXPXI'
      + expected - actual

      -P-7K956295LM2452841L6362BA
      +P-2F864278U36749846L4PXPXI

      at Context.it (test/test.js:218:32)
      at processTicksAndRejections (internal/process/task_queues.js:86:5)
Maybe its because the script? I'm running env-cmd -f ./config/dev.env mocha --timeout 10000 --bail
Peter Müller
@Munter
@IGMontero you're telling mocha to bail on the first error
Ignacio Montero
@IGMontero
Oh! Damn, I misunderstood. It's working propely without bail. Thank you!
Dmytro Kuznetsov
@dkuznetsov21

Hi !

How to run mocha-teardown with parallel?
I need to run 15 requests after all my tests(specs).

image.png
Juerg B.
@juergba
@dkuznetsov21 you can try global-fixtures.
Dmytro Kuznetsov
@dkuznetsov21
thank u
Arjun Biju
@Arrow66
hi all
i am trying to do test using mocha on create react app with craco and antd
throwing this error You are using a whole package of antd, please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size.
my configuration is -
{ "diff": true, "extension": ["js"], "package": "./package.json", "reporter": "mocha-sonarqube-reporter", "reporter-option":["output=xunit.xml"], "slow": 75, "timeout": 2000, "spec": ["src/**/*.test.js"], "ui": "bdd", "watch-files": ["src/**/*.test.js"], "watch-ignore": ["lib/vendor","node_modules/*"], "recursive":true, "color":true, "require":["jsdom-global/register","@babel/register","ignore-styles"] }
already added plugins to babel.config.js
module.exports = {presets: ["@babel/preset-react"],plugins:[ ["module-resolver", { "root": ["./src"], "alias": { "test-utils":"./src/utils/testutils/index.js" } }],["@babel/plugin-transform-modules-commonjs"],["import", { "libraryName": "antd", "style": true }]]}
Arjun Biju
@Arrow66
i dont know where did i go wrong ?
someone help
Dmytro Kuznetsov
@dkuznetsov21
hey
How to find a state about a test?
const state = this.currentTest.state; doesn't works in the new mocha (
Dmytro Kuznetsov
@dkuznetsov21
            const title = this.test.ctx.currentTest.title;
            const state = this.test.ctx.currentTest.state;