Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 17:05
    stale[bot] closed #4098
  • 11:07
    New Donation: CodeFund gave USD 6.91 to MochaJS! [Thank that person on Twitter]
  • 09:19
    giltayar synchronize #4038
  • 08:31
    giltayar synchronize #4038
  • 08:09
    giltayar synchronize #4038
  • Dec 04 18:44
    JosejeSinohui synchronize #4112
  • Dec 04 18:08
    TheRoSS opened #4119
  • Dec 04 18:08
    TheRoSS labeled #4119
  • Dec 04 17:52
    kylef opened #4118
  • Dec 04 15:53
    giltayar synchronize #4038
  • Dec 04 15:04
    giltayar synchronize #4038
  • Dec 04 14:50
    giltayar synchronize #4038
  • Dec 04 14:41
    giltayar synchronize #4038
  • Dec 04 14:31
    giltayar synchronize #4038
  • Dec 04 12:53
    giltayar synchronize #4038
  • Dec 04 12:36
    giltayar synchronize #4038
  • Dec 04 10:05
    giltayar synchronize #4038
  • Dec 04 09:48
    giltayar synchronize #4038
  • Dec 04 06:25
    giltayar edited #4038
  • Dec 04 03:59
    New Donation: Crossword King gave USD 2 to MochaJS!
pratikt1988
@pratikt1988

I've a test where:
1st process time completion time : 2019-12-08 00:00:10.000
2nd process time completion time : 2019-12-08 00:00:20.000

I've to validate if the timestamp b/w two process should be close with each other or in between? is there any way i can acheive this?

Tural Sadık
@tsadigov
for typescript or any transcompiled language, if there is a js version of the file does mocha use the existing file or does it transcompile any way?
Craig Taub
@craigtaub
@tsadigov not sure i follow, but we have an example Typescript setup https://github.com/mochajs/mocha-examples/tree/master/typescriptl have a look and see if that answers your question.
Tural Sadık
@tsadigov
thanks a lot @craigtaub . I change my moduleloader in tsconfig using AMD for using in browser and common for running node/mocha tests. Noticed that if I have my AMD/compiled js files in the directory mocha does not use transcompiler and tries to use those files with error ReferenceError: define is not defined.
When I delete generated files and npm test it runs ok
it kind of makes sense to load the file if it already exists to save computing/time. But I want to disable this. By the after successful test execution there are no transcompiled files in the directory, so probably everything is done in memory.
Tural Sadık
@tsadigov
Yesterday I solved my problem
It was because of the ts-node I am using
if there is a js file with the same name as ts file, ts-node assumes that it is ready for usage and does not transcompile using existing file. I could not find an option in ts-node to override this and I modified ts-node to match my need.
philicia
@tirzahtoh_twitter
Hi I have 2 test.spec.js tc1.spec.js and tc2.spec.js, then I do npm test, it only run tc1.spec.js not tc2.spec.js, how to make mocha run all the spec.js file? in my package.json, I have this "scripts": {
"test": "mocha --reporter mocha-teamcity-reporter $(find test -name '*.spec.js')"
}
Craig Taub
@craigtaub
@tirzahtoh_twitter try mocha --reporter mocha-teamcity-reporter *.spec.js.
Anders Moberg
@AndersMoberg

Should I be able to pass along Promises to Mocha and have the fulfillment / rejection of said Promise be used as the result for the it? Because the below testing is appearntly succeeding, whilst giving me UnhandledPromiseRejectionWarning in Node.. My presumption is that a rejection of a Promise should be a failing test.

it("should fail", function () { return Promise.reject(); })

Craig Taub
@craigtaub
tried on node v12.2 + mocha v6 and 1 failing
Anders Moberg
@AndersMoberg
@craigtaub I'm on node 10 with mocha v7 and that is failing (as in, test succeeds, Node assertion) for me.. I guess our Babel setup might be a bit busted.
Craig Taub
@craigtaub
@AndersMoberg to check with a working babel example pull https://github.com/mochajs/mocha-examples/tree/master/babel and add your test.
KiT
@KiT-Maverik

Hey guys!
In Chrome 76 they disabled 'disable-infobars' flag.
I found and replacement for this,

https://cloud.google.com/docs/chrome-enterprise/policies/?policy=CommandLineFlagSecurityWarningsEnabled

...but can't get how can I pass this in chrome args. Can anybody advise?

Lars Willighagen
@larsgw
I'm getting the error "--reporter <reporter>" can only be specified once, did that change somewhat recently (say 6.0.0)?
it did, forget to check git blame
Muhammad Haj Yahya
@mhmdmar
Hello guys, I wanted to integrate mocha unit testing with my project, when I run ">mocha test --reporter mochawesome" I get unknown reporter mochawesome
I am able to run mochawesome programmatically but I would like to run it from the cmd
any one have any clue to solve this issue ?
Craig Taub
@craigtaub
@mhmdmar with latest v6.2.0 I did below
  1. Using fresh babel example (https://github.com/mochajs/mocha-examples/tree/master/babel)
  2. npm i mochawesome
  3. mocha --reporter mochawesome
    works for me. Perhaps something with ur configuration.
Nadia
@nadiaschutz
//why my 2nd test fails? any suggestions?

/*************calculate.js************/

function calculateSquare(number, callback) {
  setTimeout(() => {
    if (typeof number !== 'number') {
     callback('Argument of type number is expected');
     return;
    }
    const result = number * number;
    callback(null, result);
  }, 1000);
}

module.exports = calculateSquare;

/*************calculate.test.js************/

const calculateSquare = require('../calculate.js');
const expect = require('chai').expect;

describe('calculateSquare', function () {
  it('should return 4 if passed 2', function (done) {
    calculateSquare(2, function (error, result) {
      console.log('callback got called');
      expect(result).to.equal(4);
      done(); // call this when Async! 
    })
  });

  it('it should return an error if passed a string', function (done) {
    calculateSquare('string', function (error, result) {
      expect(error).to.not.equal(null);
      expect(error.message).to.equal('Argument of type number is expected');
      done();
    })
  })
});
calculateSquare
callback got called
    ✓ should return 4 if passed 2 (1008ms)
    1) it should return an error if passed a string


  1 passing (2s)
  1 failing

  1) calculateSquare
       it should return an error if passed a string:

      Uncaught AssertionError: expected null to not equal null
      + expected - actual


      at /Users/nadia/test/calculate.test.js:15:28
      at Timeout.setTimeout [as _onTimeout] (calculate.js:8:5)



npm ERR! Test failed.  See above for more details.
Craig Taub
@craigtaub
@nadiaschutz error is not an object, you have passed a string.
Change callback('Argument of type number is expected’); to callback(new Error('Argument of type number is expected'));.
Or assert on error as a string.
Nadia
@nadiaschutz
@craigtaub good catch! thanks!
Craig Taub
@craigtaub
no worries
shemar dacosta
@spookyvert
Hello!
I've been having trouble with using mocha with spectron and babel
Babel isn't transpiling my components. my test script goes
"test": "mocha --require babel-core/register"
My .babelrc
 {
    "presets": [
      [
        "env",{"targets": {"node": "current"}}
      ]
    ]
  }
Tejas Deshpande
@tkdeshpande
I am looking to click through a dynamic list of links on a page and show those in the "describe" or "it" titles. Can anyone please suggest how this can be done?
Javier Pons
@JavierPons
I'm looking to how I can get the code that write passing or failing on my test. The reason is that I want to save that result in db/show it in my Frontend.
Javier Pons
@JavierPons
const assert = require("chai").assert;
const sayHello = require("../app").sayHello;
const addNum = require("../app").addNum;

//const app = require("../app");

describe("App", function() {
  it("app should return hello", function() {
    assert.equal(sayHello(), "hello");
  });
  it("app it should be a string", function() {
    assert.typeOf(sayHello(), "string");
  });
  it("should return 15", function() {
    assert.equal(addNum(8), "15");
  });
  it("should be a number", function() {
    assert.typeOf(addNum(5), "number");
  });
});
So that when Im getting the results on this simples tests and getting x passing y failing. How I can access to passing/failing text for use it as I want.
Peter Müller
@Munter
@JavierPons Switch to a different reporter with structured data. The TAP reporter or the JSON reporter might be good bets
Javier Pons
@JavierPons
@Munter Good shoot. Get it.
Peter Müller
@Munter
Javier Pons
@JavierPons
@Munter Thanks
Martin Quito
@mjquito
Hi! I'm new to Gitter. I'm trying to have mocha watch my source/project files and NOT the test files. how can I accomplish this? Also the test files and source/project files are in different directories. Thank you in advance!
Javier Pons
@JavierPons
Im running
 const mocha = new Mocha({
            reporter: "json"
          });
          const pathFile = `./test/${title}`;

          mocha.addFile(pathFile);

          const runner = mocha.run(failures => {
            console.log(failures);
            if (failures) console.log(true);
          });
console.log(runner);
in the console I get a bunch of info. I would like to manipulate that info as I want. But when I console log runner the info that I get is very different as the info mocha run and show as default in terminal. I have been looking for info on the net with no results. Is it possible to access to ReferenceError an the json file?
Javier Pons
@JavierPons
Can I manipulate all the info of running test?
Peter Müller
@Munter
@JavierPons What are you trying to do?
Javier Pons
@JavierPons
@Munter I want to access to the data that I get in terminal. I need info from that after running a test. I want to manipulate/use that info.
Mansi Jain
@supermansi
What could be the reason my mocha tests pass when individual files are run but fail when run concurrently?
dhuang612
@dhuang612
@supermansi could you provide more information there could be a ton of reasons for that.
Which tests are failing when you run them together?
Peter Müller
@Munter
@supermansi sounds like accidental shared state across tests
raghanag
@raghanag
HI All
Can you let me know how to write unit tests for typescript classes
NGUYEN Chi Thanh
@ctnguyen
Hi all