Difference between Karma and Mocha

Imagine the following scenario: Write your own test suites with Mocha Use Karma to run programmatically your Mocha tests cross-browser and cross-devices More, integrate Karma with your Jasmine existing environment Even more, integrate Karma in your Continuous Integration cycle Use a million Karma plugin to check coverage, complexity, framework stuff, etc… The power of Karma … Read more

Why do I see “define not defined” when running a Mocha test with RequireJS?

The reason your test isn’t running is because src/utils.js is not a valid Node.js library. According to the RequireJS documentation, in order to co-exist with Node.js and the CommonJS require standard, you need to add a bit of boilerplate to the top of your src/utils.js file so RequireJS’s define function is loaded. However, since RequireJS … Read more

Istanbul nyc to exclude test files

Right, after some digging I’ve managed to get this working. I’ve added “nyc”: { “include”: “app”, // Only looks in the app folder “exclude”: “**/*.spec.js” } to my package.json. Since I’m using webpack I’ll probably try and find a way of defining this rule in the webpack.config.js file (if possible at all). I’ll come back … Read more

Chai – Testing for values in array of objects

This is what I usually do within the test: var result = query_result; var members = []; result.forEach(function(e){ members.push(e.title); }); expect(members).to.have.members([‘expected_title_1′,’expected_title_2’]); If you know the order of the return array you could also do this: expect(result).to.have.deep.property(‘[0].title’, ‘expected_title_1’); expect(result).to.have.deep.property(‘[1].title’, ‘expected_title_2’);

Mocha + TypeScript: Cannot use import statement outside a module

Had the same issue and almost gave up using Mocha with TypeScript (in our case Angular 9). This is what helped me: In tsconfig.json: Replaced this: “module”: “esnext”, with this: “module”: “commonjs”, Also here I found a working example of Mocha with TypeScript and used the tsconfig file from there to compare with mine: https://medium.com/@RupaniChirag/writing-unit-tests-in-typescript-d4719b8a0a40

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)