Questions tagged [chai]

Chai is a BDD/TDD assertion library for Node.js and browsers that can be used with any Javascript testing framework.

Chai is a / assertion library for and that can be used with any testing framework.

2953 questions
1
vote
0 answers

How do I test local variables in AngularJS

I have a controller that looks like this: terminalController.controller('CashAcceptorController', [ 'PaymentService', '$rootScope', '$scope', 'PayingInfo', '$interval', '$location', function (PaymentService, $rootScope,…
1
vote
1 answer

AngularJs tests (Chai+Karma): some scope variables are not updated

I have a controller that sets a variable as follows: terminalController.controller('GeneralSettingsController', [ '$rootScope', '$scope', 'GeneralSettingsService', 'getGeneralSettings', function($rootScope, $scope,…
1
vote
2 answers

'then' function is not never getting called by Mocha for assertion checking

I have written the following test case in Mocha, where the my code uses Q module. var expect = require("chai").expect; var utils = require("../Utils.js"); var utils1 = require("../a.js"); var sinon = require('sinon'); var request =…
Prachi g
  • 849
  • 3
  • 9
  • 23
1
vote
1 answer

Writing test cases using Mocha and Chai

I have a following simple function: var moment = require('moment-timezone'); exports.splitIntoDays = function(from,to) { var timeIntervals = []; var interval = {}; var start = moment(from); var end = moment(to); …
Prachi g
  • 849
  • 3
  • 9
  • 23
1
vote
1 answer

unit test for angular responseError interceptor with 'notify' promise

I have angular responseError interceptor, which implements logic of resending request to server if a previous attempt was unsuccessful. Moreover the interceptor returns 'notify' promise to keep in touch about current status. return { …
Gleb Vinnikov
  • 458
  • 4
  • 13
1
vote
1 answer

Can I connect to mongoose from within a test?

I'm trying to run a chai test that connects to mongodb using mongoose, but it is failing with 'expected undefined to be an object'. I'm using the same method that I use in the functioning app. Am I connecting to the database correctly? var expect =…
Robert Talamantez
  • 117
  • 1
  • 2
  • 9
1
vote
2 answers

Why are mocha test not running? - node.js

I am working through web development with node and express from O'reilly. Testing with Mocha has just been introduced and I am trying to run 2 tests. First is a global test to verify that there is a page title, second is a page specific test to…
chris
  • 1,172
  • 12
  • 15
1
vote
2 answers

In unit test how can I compare original object with scope copy and avoid angular $$hashKey

I can explain my question in one image. In my unit test after some manipulations I want to check that $scope.data (first log message) is equal to original data object (second log message). I use mocha + chai and…
Boris Zagoruiko
  • 12,705
  • 15
  • 47
  • 79
1
vote
3 answers

ChaiJS doesn't handle exceptions

Here is a NodeJS module: var plural = function(words, num) { if (words.length != 3) { throw new Error('Wrong words array'); } var lastNum = num % 10; var second = (num / 10) % 10; if (second == 1) return words[2] …
michaeluskov
  • 1,729
  • 7
  • 27
  • 53
1
vote
1 answer

Node Module Export Returning Undefined

I am trying to create a node module to grab some posts but I am getting an undefined error. Index.js var request = require('request'); function getPosts() { var options = { url: 'https://myapi.com/posts.json', headers: { …
user2270029
  • 871
  • 14
  • 27
1
vote
1 answer

Why doesn't Angular.element/jqlite find top-level elements?

When writing a Mocha/Chai test for an angular view, I've discovered that jqlite (since I'm not using jQuery), won't find top-level elements. I've boiled this down to a simple example: /* jshint expr:true */ describe( "View", function() { 'use…
Geoffrey Wiseman
  • 5,459
  • 3
  • 34
  • 52
1
vote
1 answer

Unit Testing with React.js, d3.js and mocha/chai

I'm looking to do unit testing with react.js, d3 and mocha/chai. In order to integrate d3 with react.js, a lot of the d3 is done in componentDidMount since d3 cannot play very nicely with React's virtual DOM (similar to this…
Dennis
  • 21
  • 6
1
vote
1 answer

How to Test an optional member of an object?

What is the best technique to test an optional object member. Right now we are prefacing the expect statements with an if: if(object.member) expect(object).to.have.a.property('member').that.is.a('string'); but there must be a method that is more…
akaphenom
  • 6,728
  • 10
  • 59
  • 109
1
vote
2 answers

Node Mocha Chai Async - Everything Passing even when it should fail

I was attempting to teach myself to use a Testing framework for automating tests instead of having to do them by hand. After a bit of trial and error, I finally got the unit tests to start passing ... but now, my problem is everything is passing…
CaffeineAddiction
  • 803
  • 1
  • 14
  • 29
1
vote
0 answers

Chai with should: How to not break code that uses properties named "should"?

I am using Chai with should. Works great. However when I try to work with an object that has a property named should I run into trouble: // object under test function run() { var x = {}; console.log('typeof should:', typeof(x.should)); //…
Philipp Jardas
  • 3,222
  • 3
  • 29
  • 42