mocha

How do I make asynchronous calls in an event handler

自古美人都是妖i 提交于 2020-01-15 04:59:46
问题 I'm trying to write a custom mocha reporter that integrates with a 3rd party that has a HTTP API. I took the basic example given of a custom reporter (https://github.com/mochajs/mocha/wiki/Third-party-reporters) and attempted to add a call to the API in the start event handler. However, the callback for my http request to the third party never seems to fire. Example code shown below. I've tested that the request code works as expected in other contexts, it just seems to be within the event

How do I make asynchronous calls in an event handler

冷暖自知 提交于 2020-01-15 04:59:07
问题 I'm trying to write a custom mocha reporter that integrates with a 3rd party that has a HTTP API. I took the basic example given of a custom reporter (https://github.com/mochajs/mocha/wiki/Third-party-reporters) and attempted to add a call to the API in the start event handler. However, the callback for my http request to the third party never seems to fire. Example code shown below. I've tested that the request code works as expected in other contexts, it just seems to be within the event

Jest or Mocha: Dynamically create tests based on async initialization

拜拜、爱过 提交于 2020-01-14 19:00:29
问题 I'm trying to generate tests dynamically by looping over an array returned from an async call. I just cannot figure out how to do this - either using mocha or using jest. To illustrate using code, the following synchronous example works: describe("Test using various frameworks", () => { ["mocha", "jest"].forEach(framework => { it(`Should test using ${framework}`, () => { expect(true).toBe(true); }); }); }); However, if that array is fetched asynchronously, I cannot get the testing frameworks

res.status not a function when trying to set the status code

元气小坏坏 提交于 2020-01-14 10:13:10
问题 When attempting to meet the specification set by unit tests supplied, when attempting to return the status code for a method I am hit with TypeError: res.status is not a function when running the function createUser in the API implementation. It happens with every method call, such as res.send, res.sendStatus etc. Even if I add res.status() to the testing to set it there, it returns the same error. apiTests.js let chai = require('chai'); let expect = chai.expect; let sinon = require('sinon');

How to test John papa vm.model controllers and factories unit testing with jasmine?

梦想与她 提交于 2020-01-14 02:08:32
问题 Ive been using John Papa's style guide for my angular apps and Im just starting to get into the testing. However I can't seem to find any good documentation regarding testing the style with mocha, chai, and jasmine. Here is an example of one of my controllers (function () { 'use strict'; angular.module('app').controller('appController', appControllerFunction); function appControllerFunction($scope, $rootScope, $location, dataService, dataFactory) { var vm = this; function getData() { vm.data

Node.js / Express / Mocha / Supertest Rest API - Empty Request Body

房东的猫 提交于 2020-01-13 07:49:24
问题 I've looked everywhere I can to find a solution to this. The only thing I've found is an unanswered post. I apologize if I've overlooked something. The problem is that when I try to get the POST values in the /createQuestion API, the body is empty/undefined. I get errors like this Cannot read proprety 'question' of undefined coming from the API. The Express API: app.post("/createQuestion", function(req, res) { var questionType = req.body.question.type; var questionText = req.body.question

Error: This method is only meant to be run on single node. 0 found instead

无人久伴 提交于 2020-01-12 13:53:47
问题 I am testing a keybinding feature in a component. The component is rather simple, event listener for the keyup and fires up a redux action which will hide the component. I have cleaned up my code here to only relevant information. I am able to make the test pass if I just use the store dispatch to make the action call but that of course will defeat the purpose of this test. I am using Enzyme to simulate the keyup event with the appropriate event data (keycode for esc ) but I come across the

Why does the zombie.js browser return empty HTML when using Bootstrap?

感情迁移 提交于 2020-01-12 04:39:09
问题 I'm trying to test my Node.js/Express.js application using Mocha and Zombie. I can get simple tests to pass, but as soon as I add the script tags for Twitter Bootstrap to my views, the browser object returns empty HTML. Here is my test code: process.env.NODE_ENV = 'test'; var app = require('../app'); var assert = require('assert'); var Browser = require('zombie'); describe('home page', function() { before(function() { this.server = app.listen(3000); this.browser = new Browser({site: 'http:/

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

僤鯓⒐⒋嵵緔 提交于 2020-01-11 15:47:33
问题 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

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