mocha

Failing mocha test on hash of favicon static image

做~自己de王妃 提交于 2019-12-23 17:55:34
问题 I'm trying to use mocha, request, and a SHA1 hash to write an integration test to confirm that the favicon being served from Express is the same as the one on the file system. I get two different hashes, and can't figure out why. Is it possible the encoding is changing? process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" // Avoids DEPTH_ZERO_SELF_SIGNED_CERT error for self-signed certs var request = require("request"); var crypto = require('crypto'); var fs = require('fs'); var favicon = crypto

Chai deep contains assertion on nested objects

纵然是瞬间 提交于 2019-12-23 09:44:08
问题 I'm trying to assert that a object contains another one(e.i. deep equal cannot be use), but it seems that the nested ones are checked strictly. Code example: describe('Meta', function () { it('object should contains a cloned copy', function () { var obj = {a: 1, b: '2', c: {a: 2, b: '2'}}; return expect(obj).deep.contains(JSON.parse(JSON.stringify(obj))); }); }); Error message: AssertionError: expected { a: 1, b: '2', c: { a: 2, b: '2' } } to have a property 'c' of { a: 2, b: '2' }, but got {

sinon stub not replacing function

我是研究僧i 提交于 2019-12-23 09:31:31
问题 I'm trying to use sinon stub to replace a function that might take along time. But when I run the tests, the test code doesn't seem to be using the sinon stubs. Here is the code I'm trying to test. function takeTooLong() { return returnSomething(); } function returnSomething() { return new Promise((resolve) => { setTimeout(() => { resolve('ok') }, 1500) }) } module.exports = { takeTooLong, returnSomething } and this is the test code. const chai = require('chai') chai.use(require('chai-string'

Formatting objects in chai.expect errors

…衆ロ難τιáo~ 提交于 2019-12-23 09:02:03
问题 When test fails, where I'm comparing two objects using expect(x).to.deep.equal(y) , I'd like to see the actual values in my browser test report. Instead, I see something like this: AssertionError: expected { Object (x, y, ...) } to deeply equal { Object (x, y, ...) } So it doesn't really show anything useful. Is there a way to customize how chai.js formats these objects? 回答1: You can now configure the max length before an object gets truncated as per the docs: chai.config.truncateThreshold =

Testing JavaScript Click Event with Sinon

心不动则不痛 提交于 2019-12-23 07:46:44
问题 I am trying to produce some test to be able to better understand how to test DOM events with the combination of Mocha, Chai, Sinon and jQuery. I want to check that the alert function is correctly triggered on a click of the div element. I know that the setup of the HTML element is correct jQuery, but I'm not entirely sure how to produce a passing test for the code below. What's particularly strange is that I get a dialogue appearing on opening the HTML file in my browser, so I know the line '

Ensuring server app runs before mocha tests start

主宰稳场 提交于 2019-12-23 07:19:07
问题 This is similar to Ensuring Express App is running before each Mocha Test , but the specified solution still isnt working + i'm using a websocket server in short , i'm using a websocket framework called socketcluster and this is my server file import {SocketCluster} from 'socketcluster'; const socketCluster = new SocketCluster({ workers:1, brokers:1, port: 3000, appName:null, initController: __dirname + '/init.js', workerController: __dirname + '/worker.js', brokerController: __dirname + '

TypeScript: Could not find a declaration file for module in unit tests, only

北城余情 提交于 2019-12-23 04:16:07
问题 I'm using TypeScript with Visual Studio Code on Windows 10 to develop an NPM module. I use mocha/chai combined with nyc (istanbul) for unit testing and code coverage. For some of my tests I would like to use chai-bytes to compare buffers more easily. Unfortunately, there is no type definition file in the chai-bytes module and there is no definition at @types/chai-bytes available. Therefore, I have written my own type definition file for the chai-bytes plugin (which is very simple), but during

Error while debugging NodeJs program using mocha

為{幸葍}努か 提交于 2019-12-23 03:04:33
问题 I have written some test cases and I am trying to debug the test cases using using mocha and node debug. I have mocha installed on my machine I installed node-debug npm install -g node-debug Then I am running test by this command: node-debug _mocha test.js This opens a browser window, but I am getting following error Detached from the target Remote debugging has been terminated with reason: Error: connect ECONNREFUSED. Is node running with --debug port 5858? Please re-attach to the new target

vscode react+typescript + mocha: breakpoints not hit

[亡魂溺海] 提交于 2019-12-23 02:57:15
问题 I am trying for many days now to have typescript breakpoints hit in my mocha tests with no success. They keep getting hit in the .js files, not the typescript source files. I am using vscode 1.9.1. I have already asked a similar question here with yet no answer yet. I am been reading several similar issues here on stackoverflow and on google. No solution has worked for me. Here is a screenshot of the breakpoint been hit in the .js file , not the typescript: This file is a read-only file which

Sinon/Mocha test with async ajax calls didn't return promises

女生的网名这么多〃 提交于 2019-12-22 11:27:38
问题 I'm writing some test for my client side api use karma with Mocha and Sino . But I'm stuck on getting the async process. import api from '../../../src/api'; import stubData from '../data'; import axios from 'axios'; /* eslint-disable prefer-arrow-callback,func-names */ describe('API test', function () { before(function () { this.server = sinon.fakeServer.create(); }); after(function () { this.server.restore(); }); it('Should return cart with provided token', function (done) { this.server