Questions tagged [mocha]

Mocha is a feature-rich JavaScript test framework running on node.js and the browser. Mocha allows you to use any assertion library you want, if it throws an error, it will work. This means you can utilize libraries such as should.js, node's regular assert module, or others.

Filter by
Sorted by
Tagged with
3 votes
0 answers
179 views

Fetch JSON from several URLs

The exercise is Write a JavaScript package that is able to: fetch an array of URLs which contain JSON data return their contents in a promise I have already made a solution to this exercise, but I ...
Zubair97's user avatar
2 votes
0 answers
35 views

A function that opens and returns the contents of a file and some tests for it

I have the files "locale/{languageCode}.json" saved as part of the project, the reason that I made the read synchronous is because I think it is better that the internationalisation library ...
opr's user avatar
  • 121
2 votes
0 answers
39 views

Mocha chai tests

I want to have a test fail, because the email already exists, so I create [email protected] and [email protected], but is there a way to do it without this? ...
Ibn Rushd's user avatar
  • 245
3 votes
1 answer
97 views

Correct way to unit-test express API

I wrote an express API for a document management service (repo to be found here) and even though I understand the importance of unit-testing I never quite managed to wrap my head around how I would ...
Felix Wieland's user avatar
-2 votes
1 answer
46 views

Mocha with overlapping tests [closed]

Fairly new to writing tests. I hoping to get feedback about test writing. I am curious to know if there is a convention/standard for short is better or more informative is better? A) expect(mqError)....
terary's user avatar
  • 95
1 vote
1 answer
277 views

Mocha + chai tests

I have been making an effort to add a fair amount of unit testing into my code. However, I find myself going against the DRY principle quite a bit. I am currently running tests on my API with my ...
Jason McFarlane's user avatar
1 vote
1 answer
82 views

Unit tests for a simple function thats part of a public API [closed]

Given I have to write a simple function that essentially just does a http-fetch to the given URL but is part of a public API that will be used by thousands. I have two main questions about the ...
ThatBrianDude's user avatar
1 vote
1 answer
76 views

Javascript assignment as expression in fat-arrow one-liner [closed]

I have a promise where I'm taking the eventual result from the callback and storing it in a value that's scoped outside of the current block in a before hook, all ...
yurisich's user avatar
  • 654
2 votes
2 answers
1k views

RESTful CRUD application API Unit Tests

So I am trying to learn TDD/BDD with Javascript. I am creating a simple RESTful web app that uses GET, POST, PUT, and DELETE API calls to update data in a MongoDB database, and wanted to see if there ...
GoldenOats's user avatar
6 votes
1 answer
162 views

Support static typing / analysis with dependency injection

I am working on creating a test library, and I found DI to be pretty convenient, maybe even to create more functional coding patterns. Normally we can have an awkward before-hook setup in Node.js ...
Alexander Mills's user avatar
10 votes
1 answer
180 views

A Makefile to make some Cheese

Excuse the pun in the title, the project this is for is called "Cheddar" (a type of cheese). Github I have recently been writing a language, in which I was using grunt. Grunt was very slow for me, ...
Downgoat's user avatar
  • 902
13 votes
1 answer
255 views

Generate a URL, shorten it, insert it in a tex file and compile those tex files

I have written a NodeJS module and its tests to generate a URL, shorten it with Bitly, insert the short link in a tex file, compile these tex files to PDF and then merge them into one. The code is ...
springloaded's user avatar
4 votes
1 answer
98 views

Testing code that changes the DOM on page load [closed]

I am in the process of writing tests for my JS code with CasperJS and Mocha. I have a function that changes the DOM and gets run on page load (through jQuery's ...
Nathan Jones's user avatar
3 votes
1 answer
864 views

Unit testing Backbone Model

I would like to hear other people's opinion on how I unit tested a functionality in a Backbone Model. As you see below, the code under test, upon being called to toggle, toggles its completed state ...
SBel's user avatar
  • 306
7 votes
2 answers
491 views

Am I implementing BDD correctly?

I'm writing a utility that validates fields. I decided to try my hand at Behaviour Driven Development (BDD). The validator utilises "rules" to determine if field is valid. Three different types of ...
user avatar
3 votes
1 answer
1k views

Am I using Q the right way or is there a better way to do what I'm doing?

I'm using Q to flatten out some callbacks in my unit tests and return a promise to mocha (which knows to wait until the promise is resolved before running the next test). Originally I had this code: ...
CatDadCode's user avatar
15 votes
2 answers
5k views

Test mongoose model

I have mongoose model: ...
Naor's user avatar
  • 515