chai

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

南楼画角 提交于 2019-12-11 16:05:08
问题 My code: const assert = require('assert'); const ganache = require('ganache-cli'); const Web3 = require('web3'); const web3 = new Web3(ganache.provider()); const { interface,bytecode} = require('../compile'); let accounts; let inbox; beforeEach( async() => { accounts = await web3.eth.getAccounts(); inbox = await new web3.eth.Contract(JSON.parse(interface)) .deploy({data: bytecode,arguments:['Hi There !'] }) .send({from: accounts[0], gas:'1000000'}); }); describe("inbox", () => { it('deploys a

How to test a get/post api with mocha and chai using authentication

橙三吉。 提交于 2019-12-11 15:24:37
问题 I am testing some get and post apis of my node js application using mocha and chai. So far, I have been running it in my localserver and the sample code for each of post and get api is given below : process.env.NODE_ENV = 'test'; var mongoose = require("mongoose"); var db_model = require('../models/myproject.model'); var chai = require('chai'); var chaiHttp = require('chai-http'); var server = require('../app'); var should = chai.should(); var expect = chai.expect; chai.use(chaiHttp);

Should I mount using beforeEach() and set props for each test or mount a specific component at the start of each test? (using Enzyme, Chai and Mocha)

情到浓时终转凉″ 提交于 2019-12-11 15:14:10
问题 I've recently starting programming. I'm on a team who is programming in React and is using Enzyme, Mocha and Chai for unit testing. See package versions below. When testing a component where there are several use cases that require different prop values, should I use beforeEach() and then setProps() in each test, or should I do an explicit mount() (or shallow()) at the start of each test? Does it matter? For example, I could use beforeEach() to mount without any props and then use setProps()

Cucumber Protractor times out after using then() on elements selected using Protractors element function

与世无争的帅哥 提交于 2019-12-11 14:58:32
问题 I have an issue which description matches perfectly with I am not able to identify elements using protractor in angular 2 application but for me the problem is not fixed by adding # before the id value Here is the code below: When('I select my input box', (callback) => { let inputbox = element(by.css('#roomWidthInput')); console.log('inputBox promise set'); var scrpt = "return document.getElementById('roomWidthInput');"; browser.executeScript(scrpt).then(function (text) { console.log('info',

When testing async functions with Mocha/Chai, a failure to match an expectation always results in a timeout

雨燕双飞 提交于 2019-12-11 09:58:42
问题 For example, I have something basic like this: it.only('tests something', (done) => { const result = store.dispatch(fetchSomething()); result.then((data) => { const shouldBe = 'hello'; const current = store.something; expect(current).to.equal(shouldBe); done(); } }); When current does not match shouldBe , instead of a message saying that they don't match, I get the generic timeout message: Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test. It's as if

Jest check if an elements attribute exists

笑着哭i 提交于 2019-12-11 07:32:01
问题 I want to check with jest if the following svg path element contains the attribute d <path id="TrendLine" fill="none" stroke="black" d="M170,28.76363636363638C170,28.76363636363638,221.46221083573664,189.150059910"></path> How do I use jest to search for specific attribute in an element? 回答1: You can use enzyme's shallow method to render your component and then to check the props on the path element: // at the top of your test file file: import { shallow } from 'enzyme'; ... it('should render

Use ChaiHttp with beforeEach or before method

你离开我真会死。 提交于 2019-12-11 07:26:53
问题 I have an NodeJS Express application which I want to unit test which uses cookies. So I want to use a beforeEach or before to create the Cookie. Code which works without any problem (but without the before method): import * as chai from 'chai'; import { expect } from 'chai' import chaiHttp = require('chai-http'); import { app } from '../../server'; describe('Relaties', () => { describe('Ophalen alle relaties met: GET /api/ehrm-klantnr/relatie', () => { it('should get alle relaties', (done) =>

Chai doesn't recognize content-type “application/javascript”

人盡茶涼 提交于 2019-12-11 05:00:28
问题 No matter what my server actually returns, Chai always gives me res.body={} if the content-type is "application/javascript". Here is my server: const http = require('http'); const server = http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "application/javascript"}); response.end('console.log("test");'); }); module.exports = server; server.listen(process.env.PORT || 8000); console.log("Server running at http://localhost:8000/"); It outputs console.log(

Running Mocha on the command line and Including a file

南笙酒味 提交于 2019-12-10 20:31:56
问题 I’m trying to setup some JS Unit tests using Mocha, and Ideally, I'd like to run this via the command line oppose to a web page. ( TL:DR; at the bottom) First I did some bullshit test to confirm that Array worked as expected which I pulled directly from Mocha's page http://visionmedia.github.io/mocha/#getting-started and this worked as expected. At this point, to up the stakes I then created a new file /src/cow.js : /** This example is taken from https://nicolas.perriault.net/code/2013

How to test for thrown error with Chai.should [duplicate]

泄露秘密 提交于 2019-12-10 16:59:22
问题 This question already has answers here : Mocha / Chai expect.to.throw not catching thrown errors (6 answers) Closed 2 years ago . I'm using Chai.should and I need to test for an exception, but whatever I try, I cannot get it to work. The docs only explain expect :( I have this Singleton class which throws an error if you try new MySingleton(); Here is the constructor that throws the error constructor(enforcer) { if(enforcer !== singletonEnforcer) throw 'Cannot construct singleton'; ... Now I