Questions tagged [karma-mocha]

karma-mocha is a Karma plugin. Adapter for Mocha testing framework.

karma-mocha is A Karma plugin. Adapter for Mocha testing framework.

325 questions
124
votes
7 answers

"TS2322: Type 'Timeout' is not assignable to type 'number'" when running unit tests

I have two TypeScript packages, and one package (Package A) depends on the other (Package B). Each package has a unit test set up using Karma. When I run unit tests for each individually after installing all dependencies from NPM, the unit tests run…
dawsonc623
  • 1,841
  • 2
  • 16
  • 26
50
votes
2 answers

TypeError: expect(...).to.be is not a function

I am configuring my Karma amd mocha framework with grunt in my project. When I am running karma start I am getting below-mentioned error. I am getting this error in my console while running command : Karma start TypeError: expect(...).to.be is not a…
Javascript Coder
  • 5,691
  • 8
  • 52
  • 98
39
votes
5 answers

Karma, PhantomJS and es6 Promises

I am writing a JavaScript library that uses the new es6 promises. I can test the library in Firefox because promises are defined. However, when I try to test my code with Karma and PhantomJS, I get the error Can't find variable: Promise.. I am…
Travis Parks
  • 8,435
  • 12
  • 52
  • 85
36
votes
1 answer

Difference between Karma and Mocha

I am new to the Javascript world, being majorly into OOP. I have tried to look up online for a clear cut distinction between Karma and Mocha but in vain. I know Karma is a Test Runner and Mocha is a unit testing Framework, but Mocha also has its own…
Setafire
  • 719
  • 2
  • 9
  • 21
26
votes
11 answers

No binary for PhantomJS browser on your platform. Please, set "PHANTOMJS_BIN" env variable

My package.json looks like this.. "karma-phantomjs-launcher": "^0.1.4", "karma-safari-launcher": "^0.1.1", "karma-sinon-chai": "~0.2.0", "karma-spec-reporter": "~0.0.16", "mocha": "~1.20.1" my npm version is 2.2.0 whay am I getting this when I run…
Sanath
  • 4,774
  • 10
  • 51
  • 81
22
votes
2 answers

How to write a post request test in mocha with data to test if response matches?

Question: How do would I write a post request test in mocha that tests if the response matches? The response will just be a url string as it is a redirect for a 3rd party service. Working Example Payload: curl -H "Content-Type: application/json" -X…
Armeen Moon
  • 18,061
  • 35
  • 120
  • 233
16
votes
5 answers

nock is not intercepting my request

I'm trying to create some basic tests using karma server and nock. It seems like nock is not intercepting my requests at all, does anyone have idea? I can't figure out what is missing. I still getting real data. nock('https://api.github.com/users/'…
nico.amabile
  • 465
  • 1
  • 3
  • 12
14
votes
3 answers

Karma and React, have warnings to cause errors

I am using Karma with mocha to test my React components. I have some warnings displayed when the PropTypes are not matched. However it would be really interesting to have these warnings to cause an actual error, as to track down the test and fix it.…
gcedo
  • 4,811
  • 1
  • 21
  • 28
13
votes
1 answer

Angular Karma console.log does not work

I am using Karma Angular Mocha Chai in my project. I am doing TDD and would like to test my changes. I did a console.log in my test.js file but karma console does not show that. I'm not sure how to even enable that? Here is my…
fscore
  • 2,567
  • 7
  • 40
  • 74
11
votes
1 answer

Explain karma unit test times

I've been searching the web for this for two days and I found nothing. Maybe I'm looking in the wrong way — I don't know... So here it is: what are the times on my console when running a Karma+Jasmine+phantomJs unit test? ... Executed 1 of 1 SUCCESS…
11
votes
3 answers

Mocha unit tests running with Karma - done() is not defined

I'm trying to get tests written with Mocha to work running Karma, and they sort of work, but I cannot use the done() method to implement async tests, which essentially makes the tools useless to me. What am I missing? karma.conf.js module.exports =…
Jason Boyd
  • 1,192
  • 1
  • 9
  • 19
9
votes
3 answers

Karma can't load webpack

I'm getting this error; 16 07 2015 13:03:52.741:WARN [preprocess]: Can not load "webpack"! Error: Can not resolve circular dependency! (Resolving: preprocessor:webpack -> webpackPlugin -> preprocessor:webpack) My karma.conf looks like; var…
Bulkan
  • 2,555
  • 1
  • 20
  • 31
8
votes
0 answers

how to import es6 modules in karma

I'm trying to do some testing with karma, mocha and chai. I'm confused how to import es6 module correctly in karma. I am already use karma-babel-preprocessor. Could anyone help me, thanks a lot! Here is the error when run npm test Here is my…
smilebuz
  • 347
  • 5
  • 17
8
votes
2 answers

Unit testing HTTP request with Vue, Axios, and Mocha

I'm really struggling trying to test a request in VueJS using Mocha/Chai-Sinon, with Axios as the request library and having tried a mixture of Moxios and axios-mock-adaptor. The below examples are with the latter. What I'm trying to do is make a…
Lee Davies
  • 313
  • 1
  • 5
  • 9
8
votes
1 answer

How to fix the error 'ReferenceError: Can't find variable: require' when running unit test in Karma, Webpack, PhantomJS

I ma using Karma, Webpack, enzyme, PhantomJS to test my react project. When I run below command to run the test cases, ./node_modules/karma/bin/karma start config/karma.conf.js --single-run --browsers PhantomJS I got below error: PhantomJS 2.1.1…
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
1
2 3
21 22