chai

Mocha API Testing: getting 'TypeError: app.address is not a function'

对着背影说爱祢 提交于 2020-01-11 15:47:06
问题 My Issue I've coded a very simple CRUD API and I've started recently coding also some tests using chai and chai-http but I'm having an issue when running my tests with $ mocha . When I run the tests I get the following error on the shell: TypeError: app.address is not a function My Code Here is a sample of one of my tests ( /tests/server-test.js ): var chai = require('chai'); var mongoose = require('mongoose'); var chaiHttp = require('chai-http'); var server = require('../server/app'); // my

cucumber-js and Chai how to expect if element with given selector exist in DOM

可紊 提交于 2020-01-11 04:53:12
问题 I have a problem with cucumberjs. I cannot find a way to ensure that element with given selector is presented into DOM. I'm using cucumberjs with Chai. https://github.com/cucumber/cucumber-js isPresent returns object - no matter if the element exists or not. So the question is how to check if element is present in DOM. I will edit the question to share one learned lesson. I read the documentation also want to thanks to Nathan Thompson. isPresent() returns a promise that will resolve to

How to test for a propety of a class after promise resolution with mocha and chai

半腔热情 提交于 2020-01-07 06:25:53
问题 I am trying out a bit of unit testing with Mocha + Chai as promised 'use strict'; var chai = require('chai').use(require('chai-as-promised')) var should = chai.should(); describe('Testing how promises work', () => { it("should work right", function(){ class SomeClass { constructor() { this.x = 0; } getSomething(inputVal) { let self = this; return new Promise((resolve, reject) => { setTimeout(function(){ if(inputVal){ self.x = 1; resolve(); } else{ self.x = -1; reject(); } }, 10); }); } } var

Strange ghost properties being sent to Proxy get method

杀马特。学长 韩版系。学妹 提交于 2020-01-07 04:44:07
问题 This is the code that's causing the error: console.log(objectWithProxyProperty); the error that I am dealing with is either, TypeError: Cannot read property 'apply' of undefined or Error: The assertion library used does not have a 'inspect' property or method. depending on which checks I use, which is demostrated in the code below. What's clear is that the 'inspect' property is being sent to the get method, but 'inspect' is not a Symbol AND 'inspect' cannot be read with prop in chaiAssert

how to test promise returning functions

独自空忆成欢 提交于 2020-01-06 06:35:26
问题 I have following async function that return Promise. static getAccessToken(env: DeploymentEnv, username: string, password: string): Promise<AccessToken>; Now, this the unit test that I wrote for it. it("should be able to get access token",async ()=>{ let accessToken = await IModelHubServiceBusClient.getAccessToken('QA', 'abc@xyz.com', 'abc')!; assert.exists(accessToken); }); When run it, it fails the test saying the following error: should be able to get access token: Error: Timeout of 2000ms

how to test promise returning functions

时光总嘲笑我的痴心妄想 提交于 2020-01-06 06:35:14
问题 I have following async function that return Promise. static getAccessToken(env: DeploymentEnv, username: string, password: string): Promise<AccessToken>; Now, this the unit test that I wrote for it. it("should be able to get access token",async ()=>{ let accessToken = await IModelHubServiceBusClient.getAccessToken('QA', 'abc@xyz.com', 'abc')!; assert.exists(accessToken); }); When run it, it fails the test saying the following error: should be able to get access token: Error: Timeout of 2000ms

How do I write tests for an MQTT client?

天大地大妈咪最大 提交于 2020-01-04 07:25:12
问题 I'm new to MQTT and testing and am unsure how the two should work together. I'm using mqtt.js and want to write some basic tests. How should I structure them? More specifically, do I need to mock the MQTT broker, or can I make a live connection? Should that connection be to a test service like HiveMQ, etc, or to the broker I'm setting up myself? My setup: I'm building a chat application. 3 docker containers. 1 broker (using mosquitto, 2 clients. Clients are using mqtt.js within a script that

Testing for an Asynchronous throw in Mocha

扶醉桌前 提交于 2020-01-04 03:01:27
问题 I have a block of code that tries to reconnect to Redis if a connection breaks. If it can not re-establish connection, it throws an error. I am trying to test the block of code that throws the error, but I am unable to write a successful test using mocha and chai. My test looks like this: it('throws an error when a connection can\'t be established', function (done) { var c = redisClient.newClient(); c.end(); sinon.stub(redisClient, 'newClient', function () { return { connected: false }; });

How to test methods and callback using Mocha, Chai, & Enzyme in React-Redux

不羁岁月 提交于 2020-01-01 12:27:40
问题 I have to write unit test cases for a PlayerList container and Player component. Writing test cases for branches and props is OK, but how do I test the component's methods and the logic inside them. My code coverage is incomplete because the methods are not tested. Scenario: Parent component passes a reference to its method onSelect as a callback to child component. The method is defined in PlayerList component, but Player is generating the onClick event that calls it. Parent Component

Chai test array of objects to “contain something like” an object submatch

微笑、不失礼 提交于 2019-12-31 01:39:09
问题 Ok. I've tried to read other questions here but still didn't find a straightforward answer. How can I assert a partial object match in an array using chai? Something like the following: var expect = require('chai').expect; var data = [ { name: 'test', value: 'bananas' } ]; expect(data).to.be.an('array').that.contains.somethig.like({name: 'test'}); Just to clarify, my intention is to get as close to the example provided as possible. to chain after the .be.an('array') and to provide only the