mocha.js

Counting elements with the same selector in webdriver.io

可紊 提交于 2021-01-26 14:51:41
问题 I am using webdriver.io with chai and mocha for testing. In one of my tests I need to count how many elements with the same CSS class are in the page. None of the webdriver.io API seems to return an array. How can it be achieved? 回答1: This is how you do it: client.elements('.myElements', function(err,res) { console.log('element count: ',res.value.length); }); Explanation: with elements you fetch all elements according given selector. It returns an array of webdriver elements which represents

Counting elements with the same selector in webdriver.io

ε祈祈猫儿з 提交于 2021-01-26 14:51:19
问题 I am using webdriver.io with chai and mocha for testing. In one of my tests I need to count how many elements with the same CSS class are in the page. None of the webdriver.io API seems to return an array. How can it be achieved? 回答1: This is how you do it: client.elements('.myElements', function(err,res) { console.log('element count: ',res.value.length); }); Explanation: with elements you fetch all elements according given selector. It returns an array of webdriver elements which represents

Does mocha/supertest create express server for each test suite?

夙愿已清 提交于 2021-01-25 04:09:47
问题 I have been using mocha , supertest and proxyquire since last few days. I am able to do integration test with no problem. But I have some questions. This is one test suite from my project. const expect = require('chai').expect const request = require('supertest') const _ = require('lodash') const sinon = require('sinon') const faker = require('faker') describe('ComboController /api/v1/combos', function () { const app = require('../src/app') it('should GET combo of given id: getComboById',

Does mocha/supertest create express server for each test suite?

我的未来我决定 提交于 2021-01-25 04:06:20
问题 I have been using mocha , supertest and proxyquire since last few days. I am able to do integration test with no problem. But I have some questions. This is one test suite from my project. const expect = require('chai').expect const request = require('supertest') const _ = require('lodash') const sinon = require('sinon') const faker = require('faker') describe('ComboController /api/v1/combos', function () { const app = require('../src/app') it('should GET combo of given id: getComboById',

testing fetch with mocha and chai

≯℡__Kan透↙ 提交于 2021-01-23 06:50:27
问题 I have the following example test: import { assert } from 'chai' function starWarsMovies () { fetch('http://swapi.co/api/films/') .then((res) => { return res.json() }) .then((res) => res.count) } describe('Get star war movies', () => { it('should get 7', () =>{ assert.equal(starWarsMovies(), 7) }) }) But I getting ReferenceError: fetch is not defined What do I have to use in order to test a fetch request. UPDATE I also tried: import { polyfill } from 'es6-promise' import fetch from

Mocha before and after hooks not executing

时光总嘲笑我的痴心妄想 提交于 2021-01-21 11:16:52
问题 I am trying to run a simple test on my local cassandra database to check if the select statement returns the correct no of records from the table. However, the code placed between the before and after blocks are not getting called. As a result my test simply fails. var assert = require('assert'); var cassandra = require('cassandra-driver'); var async = require('async'); //Connect to the cassandra cluster, assuming that the keyspace & columnspace already exists var client = new cassandra

Mocha before and after hooks not executing

跟風遠走 提交于 2021-01-21 11:14:15
问题 I am trying to run a simple test on my local cassandra database to check if the select statement returns the correct no of records from the table. However, the code placed between the before and after blocks are not getting called. As a result my test simply fails. var assert = require('assert'); var cassandra = require('cassandra-driver'); var async = require('async'); //Connect to the cassandra cluster, assuming that the keyspace & columnspace already exists var client = new cassandra

Mocha before and after hooks not executing

笑着哭i 提交于 2021-01-21 11:11:31
问题 I am trying to run a simple test on my local cassandra database to check if the select statement returns the correct no of records from the table. However, the code placed between the before and after blocks are not getting called. As a result my test simply fails. var assert = require('assert'); var cassandra = require('cassandra-driver'); var async = require('async'); //Connect to the cassandra cluster, assuming that the keyspace & columnspace already exists var client = new cassandra

Node.js Mocha Testing Restful API Endpoints and Code Coverage

爷,独闯天下 提交于 2021-01-21 09:21:00
问题 I've been really enjoying Istanbul and experimenting with other Node.js coverage libraries as well, but I have an issue. Nearly all of my unit tests are HTTP calls to my API like so: it('should update the customer', function (done) { superagent.put('http://myapp:3000/api/customer') .send(updatedData) .end(function (res) { var customer = res.body; expect(res.statusCode).to.equal(200); expect(customer.name).to.equal(updatedData.name); done(); }); }); As opposed to actually requiring the

Node.js Mocha Testing Restful API Endpoints and Code Coverage

为君一笑 提交于 2021-01-21 09:20:58
问题 I've been really enjoying Istanbul and experimenting with other Node.js coverage libraries as well, but I have an issue. Nearly all of my unit tests are HTTP calls to my API like so: it('should update the customer', function (done) { superagent.put('http://myapp:3000/api/customer') .send(updatedData) .end(function (res) { var customer = res.body; expect(res.statusCode).to.equal(200); expect(customer.name).to.equal(updatedData.name); done(); }); }); As opposed to actually requiring the