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
1 answer

How To Test route.navigate on Backbone View

I'm currently developing a Backbone.js application which uses the Mocha, Chai, and Sinon libraries for testing. I'm struggling to code the following test: When a user clicks a button it should redirect the user to home. Here's how the view looks…
Diego Castillo
  • 175
  • 1
  • 15
1
vote
1 answer

Write tests for an angular REST app

I've been clueless so far. Say I have this very simple app module: var app = angular.module('myApp', []); app.service('searchService', ['$http', function($http){ var baseURL="https://someonehost.com/product/search&query="; return { …
philomath
  • 2,209
  • 6
  • 33
  • 45
1
vote
1 answer

How can I check check should contain multiple properties with chai-things?

I am looking to check an array contains an Object on my mocha tests for my Node.js application and I know with Chai-Things I can do: [{ pet: 'cat' }, { pet: 'dog' }].should.include({ pet: 'cat' }) or [{ pet: 'cat' }, { pet: 'dog'…
jonnie
  • 12,260
  • 16
  • 54
  • 91
1
vote
1 answer

UI Protractor Find & Click Select Box Based On Text Search

I am trying to find a way to search for the row that has the name X in it and then click on the checkbox in that row using UI Protractor. I have been very unsuccessful so far. If you see below, I want to search for testproxy and then click the…
1
vote
1 answer

Unit Testing a service with $http and $q using mocha, chai and sinon

I have this function and need test it using mocha, chai and sinon. This is my code: service-wiki-pelis.js 'use strict' var WikiService = function($http,$q){ return { getMovies: getMovies } function getMovies() { var…
1
vote
1 answer

Check with Chai if an object doesn't contain any additional properties

I'm working on an API and should return based on permissions only a subset of the actual object's properties. I'm writing my tests in mocha and chai and would like to test for something like this (given res is the response object from the server and…
peter
  • 14,348
  • 9
  • 62
  • 96
1
vote
1 answer

Allowing chai/mocha tests to bubble errors to process.on

I am writing a node module that catches top level uncaught errors and want to write some tests for it. Unfortunately my favorite framework seems to have some issues with intentionally throwing and catching uncaught exceptions. If I throw the…
Neablis
  • 894
  • 2
  • 12
  • 30
1
vote
1 answer

How to mock a glob call in Node.js

I'm using Mocha, Chai and Sinon JS to write Unit Tests for my Node.js application. Here is the module I want to test: var glob = require('glob'); var pluginInstaller = require('./pluginInstaller'); module.exports = function(app, callback) { …
Tineler
  • 253
  • 3
  • 17
1
vote
1 answer

Error: Could not resolve 'app.history' from state ' '

I am writing unit test which is using $stateProvider(the code is shown below for both the code and its test file).While executing this, it is giving error- "Error: Could not resolve 'app.history' from state ''". $stateProvider .state('app', …
Neha Gupta
  • 987
  • 5
  • 16
  • 35
1
vote
1 answer

chai things - comprehensive list of should() methods

I'm looking for a comprehensive list of methods you can call on a decorated object using the chai-things library for chai.js so, for example : myObject.should.METHOD_NAME. What are all of the valid METHOD_NAMEs that can be called in the above…
looshi
  • 1,226
  • 2
  • 9
  • 23
1
vote
1 answer

Testing express route methods

I'm trying to check whether res.json() is being called in a express get method. However in my get method it waits for a promise before executing res.json(); Here is the controller method: function get(req, res, next) { Service …
grimurd
  • 2,750
  • 1
  • 24
  • 39
1
vote
2 answers

mocha with expect is not working for testing errors

In the following script only one test is passing. Testing error (throw Error()) is failing with message 1) a test should throw error: var expect = require('chai').expect; describe("a test", function() { var fn; before(function() { …
Ordre Nln
  • 157
  • 3
  • 11
1
vote
3 answers

How to convert a promise in protractor to a string

I am a bit new to Protractor and Jasmine, and I am trying to check if a list of elements that I have fetched using getText() contains a particular element: Consider the following elements var productNameElements =…
Arjun Jhawar
  • 31
  • 1
  • 3
1
vote
0 answers

Unit testing angularjs with mocha/chai should.have.been.called not working

The following test passes whether my expect statement is expect(propertyFactory.readProperty).should.have.been.called; or expect(propertyFactory.readProperty).should.have.not.been.called; I've tried this with or without the sinon…
ThinkingInBits
  • 10,792
  • 8
  • 57
  • 82
1
vote
0 answers

How do I make an assertion that the value of a callback eventually changes?

I'm currently trying to write a test that asserts that after I click on an element the value of another element eventually changes. I tried the following : it 'should change the value of the ec when the Scheduled option is clicked', -> …
CodePrimate
  • 6,646
  • 13
  • 48
  • 86