chai

How can I check that two objects have the same set of property names?

流过昼夜 提交于 2019-12-28 01:49:20
问题 I am using node, mocha, and chai for my application. I want to test that my returned results data property is the same "type of object" as one of my model objects (Very similar to chai's instance). I just want to confirm that the two objects have the same sets of property names. I am specifically not interested in the actual values of the properties. Let's say I have the model Person like below. I want to check that my results.data has all the same properties as the expected model does. So in

Error: Timeout of 2000ms exceeded. For async tests and hooks. Unit test with mocha and chai

人盡茶涼 提交于 2019-12-25 09:40:48
问题 While establishing the connection using socket Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done( )" is called; if returning a Promise, ensure it resolves. Given below is the code reference of the same beforeEach(function(done) { var socketOptions = {}; var socket = io.connect("http://localhost:5000", socketOptions); socket.on('connect', function () { console.log('Connection Established'); setTimeout(done, 500); }); socket.on('error', function (err) { console.log(

How to test a custom module running node-fluent-ffmpeg (an async module)?

泄露秘密 提交于 2019-12-25 04:24:09
问题 How do I test a custom module which is simply running a node-fluent-ffmpeg command with Mocha&Chai? // segment_splicer.js var config = require('./../config'); var utilities = require('./../utilities'); var ffmpeg = require('fluent-ffmpeg'); module.exports = { splice: function(raw_ad_time, crop) { if (!raw_ad_time || !crop) throw new Error("!!!!!!!!!! Missing argument"); console.log("@@@@@ LAST SEGMENT IS BEING SPLITTED."); var segment_time = utilities.ten_seconds(raw_ad_time); var last

sinon spy on function not working

家住魔仙堡 提交于 2019-12-24 20:56:12
问题 I'm trying to write a standalone test for this simple middleware function function onlyInternal (req, res, next) { if (!ReqHelpers.isInternal(req)) { return res.status(HttpStatus.FORBIDDEN).send() } next() } // Expose the middleware functions module.exports = { onlyInternal } This does not work describe('success', () => { let req = { get: () => {return 'x-ciitizen-token'} } let res = { status: () => { return { send: () => {} } } } function next() {} let spy before(() => { spy = sinon.spy(next

Seem to Have the Wrong Content Type When POSTing with Chai-HTTP

♀尐吖头ヾ 提交于 2019-12-24 15:14:09
问题 I am looking to make use of Chai-HTTP for some testing. Naturally I want to test more than my GETs however I seem to be hitting a major roadblock when attempting to make POSTs. In an attempt to figure out why my POSTs weren't working I began hitting them against a POST test server. Here is a POST attempt formatted using an entirely different toolchain (Jasmine-Node and Frisby) for testing (that works just fine): frisby.create('LOGIN') .post('http://posttestserver.com/post.php', { grant_type:

Assert array includes array with Chai

浪尽此生 提交于 2019-12-24 11:28:13
问题 I am trying evaluate whether data returned from a table (table.getData()) which is a 2D array contains another array. In the console the expected data appears in the 2D array returned from the table.getData() call but the assertion fails. this.Then(/^I see my account balances as follows:$/, function (tableData, done) { var balanceAggregationPage = new BalanceAggregationPage(this.app.pagesContainer), table = balanceAggregationPage.getAccountsTable(); var rows = tableData.getRows(); rows.shift(

Supertest fails to test repeated post request

╄→尐↘猪︶ㄣ 提交于 2019-12-24 10:14:19
问题 I'm testing an api that creates users. The api does not allow the creation of users with the same login value. So I wrote the tests below: const app = require('../config/express'); //exports a configured express app const request = require('supertest'); const {populateUsers} = require('../seeders/users.seed'); beforeEach(populateUsers);//drop and populate database with some seeders describe('POST /v1/users', () => { it('#Post a new user - 201 status code', (done) => { request(app) .post('/v1

Unit Test a Node.js application with Mocha, Chai, and Sinon

*爱你&永不变心* 提交于 2019-12-24 07:59:22
问题 I am new to unit testing Node.js application. My application converts CSV file to JSON after some filtering. var fs = require('fs'); var readline = require('readline'); module.exports = ((year) => { if (typeof year !== "number" || isNaN(year)){ throw new Error("Not a number"); } var rlEmitter = readline.createInterface({ input: fs.createReadStream('./datasmall.csv'), output: fs.createWriteStream('./data.json') }); rlEmitter.on('line', function(line) { /*Filter CSV line by line*/ }); rlEmitter

Comparing the function output type in assertion

拈花ヽ惹草 提交于 2019-12-24 05:09:08
问题 I'm struggling with writing a test assertion using chai, mocha, and JS-DOM. I have a simple function like: function HtmlElement(el) { this.element = (el instanceof HTMLElement) ? el :document.createElement(el); } in the tests I have: it('should have addClass method', function () { const ul = (new HtmlElement('ul')); ul.element.should.be.equals('<ul></ul>'); // Outputs the actual UL }); but the error: AssertionError: expected <ul></ul> to equal '<ul></ul>' is the one I can't understand - what

Enzyme Unit tests with Webpack Externals

橙三吉。 提交于 2019-12-24 01:24:00
问题 I'm currently testing a component that relies on a an external script with webpack externals. DBPanel.js: import React, { PureComponent } from 'react'; import $ from 'jquery'; And the webpack externals file looks like this: webpack.config.js: externals: { jquery: "jQuery", Materialize: "Materialize" } When I import the the file in my test import DBPanel from '../components/DBPanel'; I get this error: Error: Cannot find module 'jquery' 来源: https://stackoverflow.com/questions/45724728/enzyme