by

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
raghanag
@raghanag
thanks @craigtaub
Matt Price
@titaniumbones

I'm a little confused about the descriptive text in an it test.

so, e.g.,

  describe('01: Variables and Functions', function() {
   let authorString;
    before( () => {authorString = "Ms. Atwood";}}
    it(`function "greeting("${authorString}")" should return "Hello, ${authorString}`, function() {
      assert.equal(fns.greeting(authorString), `Hello, `,
        'Check to make sure you have combined the strings and variables properly.');
    });

when the first parameter of it is evaluated, authorString is still undefined, but during the test, it's properly set. Am I understnading that right, and if so, is the only way to access a variable in that descriptive string to set it globally before tests start up?

Peter Müller
@Munter
@titaniumbones I recommend you name your tests so they avoid implementation details. Here you are literally duplicating your function call and assertion. Try something more high level, like it('should return a personalised greeting')
Matt Price
@titaniumbones
@Munter yes it's very inefficient, but these tests are written to help students who get very confused at the beginning of a project, so I am spelling out these first fewresults in an odd way.
so maybe it isn't a use case that makes much sense.
Maurizio Pucci
@devmao
it's possible to run test files/module in parallel and getting the right code coverage?
Peter Müller
@Munter
Currently, if you run multiple separate calls to nyc and mocha you'll need to combine the test coverage reports yourself. We have some work in progress for running parallel tests which might interest you: mochajs/mocha#4245
I am unsure if that addition allows for unified code coverage reports
Kenny
@RnzTejada
Hi, how i can migrate this html to a react component?

`<!DOCTYPE html>

<html lang="en">
<head>
<link rel="stylesheet" href=".././node_modules/codemirror/codemirror.css"/>
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="https://unpkg.com/chai@4.1.2/chai.js"></script>
<script src="https://unpkg.com/mocha@4.0.1/mocha.js"></script>
<script class="mocha-init">
mocha.setup({
ui: 'bdd',
checkLeaks:true,

})
</script> 
<!-- Aca va codigo para ejecutar -->
<script>
  ${code}
</script>
<!-- Aca va TEST para evaluar el codigo de arriba -->
<script>
   ${test}
</script>
<!-- Run del codigo y del test -->
<script class="mocha-exec">

  mocha.run((e) => console.log(e))




</script>

</body>
</html>`

Craig Taub
@craigtaub
What are you trying to do? Test a react component in the browser? There are ways to do that and use mocha as test runner
Kenny
@RnzTejada
nop, testing some code in react like codewars, and i need to migrate this for more performance
Craig Taub
@craigtaub
I do not follow what performance has to do with this. If you important mocha lib in an external script you can probably get access to it from a react component via the window and run it, still do not follow why.
Mārtiņš Tereško
@teresko
hi everyone
is there something specific one must do so that it is possible to test ES2016 code with mocha?
Mārtiņš Tereško
@teresko
basically, what I have us ES7 code, that is being transpiled using webpack/babel, I really want to start adding tests to it (before I brain someone with a keyboard), but I have no idea how to get it working
when I try to import a module in the test file, I see an error message complaining about syntax error in export default class Path { line
I don't even know what to start digging ...
Craig Taub
@craigtaub
@teresko you should have to require the babel hook in your mocha config (see https://mochajs.org/#-require-module-r-module).
If that doesnt work, we have quite a few examples of using mocha with webpack or babel apps in our examples repo, see https://github.com/mochajs/mocha-examples/.
Hope that helps.
Mārtiņš Tereško
@teresko
it didn't :D
but I got it somehow working on this attempt ... I have no idea what changed
Bhargava Reddy
@reddybhargava
I get the following error while trying to install mocha in one of my NodeJS projects using npm...
silly fetchPackageMetaData error for mocha@latest Unexpected token , in JSON at position 3969 while parsing near '...mocha","version.0.6","dependencies":{"co...'
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/local/bin/npm', 'i', 'mocha' ]
2 info using npm@6.13.6
3 info using node@v8.10.0
4 verbose npm-session 8057fbb826c81472
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 http fetch GET 304 http://registry.npmjs.org/mocha 146ms (from cache)
8 silly fetchPackageMetaData error for mocha@latest Unexpected token , in JSON at position 3969 while parsing near '...mocha","version.0.6","dependencies":{"co...'
9 timing stage:rollbackFailedOptional Completed in 1ms
10 timing stage:runTopLevelLifecycles Completed in 334ms
11 verbose stack SyntaxError: Unexpected token , in JSON at position 3969 while parsing near '...mocha","version.0.6","dependencies":{"co...'
11 verbose stack     at JSON.parse (<anonymous>)
11 verbose stack     at parseJson (/usr/local/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
11 verbose stack     at consumeBody.call.then.buffer (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50)
11 verbose stack     at <anonymous>
11 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)
Bhargava Reddy
@reddybhargava
This error comes up no matter what version of mocha i try to install
npm version: 6.13.6
node version: v8.10.0
Nico Jansen
@nicojs
probably it is wrongly cached. Try npm cache clean --force and try again
Bhargava Reddy
@reddybhargava
I tried that, didn't work.
Bhargava Reddy
@reddybhargava
I've tried deleting node_modules folder and package-lock.json file, still no luck
Nico Jansen
@nicojs
What does this command yield? npm config get registry
verilog15
@verilog15
Hello :), How do I run mocha with additional parameters?
I run my server with node server.js 58091 prod verbose but when I run mocha it runs node mocha
Peter Müller
@Munter
@verilog15 mocha exposes its own binary that you should run. npx mocha or ./node_modules/.bin/mocha
verilog15
@verilog15
yes, when I run mocha and print the process.argv it says node mocha.
The way I run the server is: node server.js <port_number> (development | production) [verbose]
The server.js starts the server, right after verifying the parameters (by checking process.argv). I'm trying to add tests with supertest and mocha. I have created a new file test.js with the following code: const server = require('../server.js');. I run my server as following: node server.js <port_number> (development | production) [verbose] The server.js starts the server, right after verifying the parameters (by checking process.argv). I'm trying to add tests with supertest and mocha. I have created a new file test.js with the following code: const server = require('../server.js'); Running mocha will fail because server.js checks that you passed that you used the right parameters. But if you run npm start test (which rusn mocha) you will get three parameters in the process.argv (which are node, server.js, and test of mocha).
Peter Müller
@Munter
I think I understand. You should separate the part of your server that is the command line interface from the part that starts the server. When you test your server in node you can't rely on command line parameters like that. So create a cli that focuses on taking inputs from the command line arguments, validate them and pass them on to the function that starts your server
The function that starts your server is the one you want to test. So inside your tests, call that function with your options directly
Yuriy Gyerts
@gyerts
Hi, how can I say to mochajs NODE_PATH variable using .mocharc.yml? I ask it because when I run tests in pycharm, pycharm has own tool to run tests, and this tool does not see any vars set in package.json, .env, etc... only one hope left is to use .mocharc.yml. Or I will spent rest of my life to set NODE_PATH manually ((
Sean Burke
@leftmostcat
I have the following mocha.opts file: https://github.com/bookbrainz/bookbrainz-data-js/blob/master/test/mocha.opts. I tried replacing this with https://pastebin.com/Dk324CLV as a .mocharc.yaml and now I get https://pastebin.com/TjqqPmJn when running mocha. What have I done wrong?
Craig Taub
@craigtaub
version of node & mocha?
Sean Burke
@leftmostcat
12.16.3 and 7.2.0 respectively.
Craig Taub
@craigtaub
@gyerts AFAIK can't set node env var in config. Can you not configure pycharm to set this env var? Alternative you could use mocha programmatically and set env var there i.e https://github.com/mochajs/mocha/wiki/Using-Mocha-programmatically and try process.env.NODE_PATH = .... but might be too late by then.
Sean Burke
@leftmostcat
Found that @babel/register wasn't installed. Installing that seems to have solved it.
Craig Taub
@craigtaub
Cool
verilog15
@verilog15
Hi guys, it there a way to catch deferred.reject() using mocha and supertest?
Maybe with chai?
Craig Taub
@craigtaub
@verilog15 with mocha + chai-as-promised you should be able to assert a promise fulfillment via return yourPromise.should.be.rejected; in the test.
Robin Denton
@Raenton
When I am running mocha ./test/unit/src/**/*.test.js via CLI, it is capturing all of my test files. However, when I create a "test": "mocha ./test/unit/**/*.test.js" in my package.json and run yarn test, the test files are only partially captured. The behaviour of manual CLI usage versus via yarn/npm script is different with all glob patterns I have tried. Is there any solution to this so that I may run my tests without manually using the CLI?
Luka Rahne
@ra1u

Running mocha over:
describe(" describe1 ", it(" it1 " , () => {} ));
describe(" describe2 ", it(" it2 " , () => {} ));

What is expected outpu?

Luka Rahne
@ra1u
In documentation I found term falsy. What is that?
raghanag
@raghanag
Hi I am using karma with mocha and this is my karma config where I mentioned the mocha.opts to generate test reports in addition to the code coverage report. but i am not seeing any reports
frameworks: ['mocha', 'requirejs', 'chai', 'fixture', 'karma-typescript'],
preprocessors: {
      './src/ts/**/*.ts': ['karma-typescript'],
      './tests/unit/**/*.ts': ['karma-typescript'],
    },
    client: {
      mocha: {
        grep: config.grep,
        opts: './tests/unit/mocha.opts'
      },
    }
--timeout=60000
--reporter mocha-multi-reporters
--reporter-options configFile=./tests/unit/report-config.json
{
  "reporterEnabled": "mocha-sonarqube-reporter, mochawesome",
  "mochaSonarqubeReporterReporterOptions": {
    "output": "reports/unit-tests/sonar/qa-test-results.xml"
  },
  "mochawesomeReporterOptions": {
    "reportDir": "reports/unit-tests/html",
    "reportFilename": "index",
    "reportTitle": "Unit Tests",
    "reportPageTitle": "Unit Tests",
    "charts": true,
    "showSkipped": true
  }
}
anything wrong with my config