Questions tagged [should.js]

should is an expressive, readable, test framework agnostic, assertion library for node.

should is an expressive, readable, test framework agnostic, assertion library for node.

GitHub project: https://github.com/visionmedia/should.js

API reference: http://shouldjs.github.io/

149 questions
6
votes
1 answer

Checking for a throw new Error with should.js and Mocha

I've got an error thrown like so: if (somethingBadHappened) { throw new Error('what were you thinking, batman?') } Now I want to write a test to check that this throws when expected: should(MyClass.methodThatShouldThrow()).throws('what were you…
brandonscript
  • 68,675
  • 32
  • 163
  • 220
6
votes
2 answers

should.js not causing mocha test to fail

I'm very new to unit tests, mocha, and should.js, and I'm trying to write a test for an asynchronous method that returns a promise. Here is my test code: var should = require("should"), tideRetriever = require("../tide-retriever"), moment =…
SimpleJ
  • 13,812
  • 13
  • 53
  • 93
6
votes
2 answers

Cannot find module './lib/should'

i have a test code and trying to run it var should = require("should") describe('Array', function(){ describe('#indexOf()', function(){ it('should return -1 when the value is not present',function(){ …
Nitin
  • 171
  • 2
  • 5
5
votes
1 answer

How to use OR condition with should() in mocha

I want to use two values to get compared so that if either is true then my test should pass.Using the below code is comapring only 1st condition and failing the test. if (typeof lng !== 'undefined') { data.lng.should.equal(lng) ||…
Shashi Kumar Raja
  • 508
  • 1
  • 8
  • 23
5
votes
1 answer

Test custom method on React component has been called, using Enzyme and Sinon

I want to check that when a button is clicked on my component, it calls the method I have created to handle the click. Here is my component: import React, { PropTypes, Component } from 'react'; class Search extends Component { constructor(){ …
Andy Briggs
  • 107
  • 1
  • 5
5
votes
3 answers

Catching thrown errors with SinonJS

I've got a method that may throw an Error, but I'm having trouble writing a SinonJS/Mocha/Should unit test case for this condition. Sample function under test: function testError(value) { if (!value) { throw new Error('No value'); return…
benjarwar
  • 1,794
  • 1
  • 13
  • 28
5
votes
1 answer

Node.js + Chai/Mocha/Should: running multiple tests against the same response

I'm using something very similar to the following to execute a series of API tests using Mocha. This is great, but it requires making a separate API call for each test. I want to use the same API call and run multiple tests against that response.…
brandonscript
  • 68,675
  • 32
  • 163
  • 220
5
votes
2 answers

Drop MongoDB database before running Mocha test

If I try to drop the database using after (at the end of my tests) it works. If I try the following: var db = mongoose.connect('mongodb://localhost/db-test') describe('Database', function() { before(function (done) { …
fusio
  • 3,595
  • 6
  • 33
  • 47
5
votes
3 answers

Chai, Mocha: Identify should assertion

I'm using mocha and chai as assertions. I have several assertions in my spec: Exp1.should.be.true Exp2.should.be.true Exp3.should.be.true If one of them fails mocha writes "expected false to be true". Is there a way to identify them? With expect I…
WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
4
votes
2 answers

How can I assert a function has `await`ed an async function using should.js

I have an async function f that calls another async function g. To test if f calls g, I'm stubbing g using sinon and assert it's been called using should.js. 'use strict'; require('should-sinon'); const sinon = require('sinon'); class X { …
snak
  • 6,483
  • 3
  • 23
  • 33
4
votes
1 answer

Issue with should.js using TypeScript

My code is: Object.keys(res.body.data).should.containEql('id') The error that TypeScript gives me is Property 'should' does not exist on type 'string[]'. So how do I use should with TypeScript?
Shamoon
  • 41,293
  • 91
  • 306
  • 570
4
votes
2 answers

Should.js chaining multiple assertions on a single property

I've got an object like this: var obj = { "uuid": "60afc3fa-920d-11e5-bd17-b9db323e7d51", "type": "candy" } I want to write a test that checks first that the object has the property 'uuid' in the first place, and then that 'uuid' is a…
brandonscript
  • 68,675
  • 32
  • 163
  • 220
4
votes
1 answer

How do I write a test for a binary download using mocha and should.js with sails.js?

I'm trying to write at test for a Sails.Js controller action that downloads a user's avatar image. The controller action looks like this: /** * Download avatar of the user with the specified id * * (GET /user/:id/avatar) */ avatar: function (req,…
fraxture
  • 5,113
  • 4
  • 43
  • 83
4
votes
2 answers

Bypass ESLint's `no-unused-var` for Should in a Mocha test

I'm using ESLint on all my files, including the test files, with a no-unused-var: true rule. I'm using Should.js in my Mocha tests, and in one of the files, I'm getting an error on the should variable. A quick comparison to the other tests shows,…
Traveling Tech Guy
  • 27,194
  • 23
  • 111
  • 159
4
votes
0 answers

Forcing Mongodb errors for unit testing in NodeJS

I'm writing my first tests for a Mongodb database using should.js, and need a way to force errors in various functions that make database calls. I've spent a little time exploring how Rewire.js might help, but am still new enough to Mongo that I'm…
1
2
3
9 10