mocha

how to test promise returning functions

独自空忆成欢 提交于 2020-01-06 06:35:26
问题 I have following async function that return Promise. static getAccessToken(env: DeploymentEnv, username: string, password: string): Promise<AccessToken>; Now, this the unit test that I wrote for it. it("should be able to get access token",async ()=>{ let accessToken = await IModelHubServiceBusClient.getAccessToken('QA', 'abc@xyz.com', 'abc')!; assert.exists(accessToken); }); When run it, it fails the test saying the following error: should be able to get access token: Error: Timeout of 2000ms

how to test promise returning functions

时光总嘲笑我的痴心妄想 提交于 2020-01-06 06:35:14
问题 I have following async function that return Promise. static getAccessToken(env: DeploymentEnv, username: string, password: string): Promise<AccessToken>; Now, this the unit test that I wrote for it. it("should be able to get access token",async ()=>{ let accessToken = await IModelHubServiceBusClient.getAccessToken('QA', 'abc@xyz.com', 'abc')!; assert.exists(accessToken); }); When run it, it fails the test saying the following error: should be able to get access token: Error: Timeout of 2000ms

Getting DialogSet.add(): Invalid dialog being added when testing

…衆ロ難τιáo~ 提交于 2020-01-06 05:47:11
问题 I'm trying to build some tests for my bot dialogs. I'm using the same test code (and modified test data) with two different bots with the identical dialog names. As such, the test.js file is the same for both bots. However, when I try to run my tests via Mocha on the second bot, I am getting an Error: DialogSet.add(): Invalid dialog being added. message for each test. This does not happen with my first bot. I even tried replacing the dialog file in the second bot with the one from the

aws-sdk s3 upload not working from mocha test

二次信任 提交于 2020-01-06 04:20:09
问题 Trying to run s3 upload from a mocha test: 'use strict'; describe('S3 test', function() { it.only('S3 test 1', function*() { var AWS = require('aws-sdk'); //AWS.config.region = 'us-west-2'; var s3 = new AWS.S3({ params: { Bucket: 'test-1-myBucket', Key: 'myKey' } }); s3.createBucket(function(err) { if (err) { console.log("Error:", err); } else { s3.upload({ Body: 'Hello!' }, function() { console.log("Successfully uploaded data to myBucket/myKey"); }); } }); }); }); but nothing happens, it is

Ember Mocha tests fail when async (using ember-mocha-adapter)

久未见 提交于 2020-01-05 12:07:29
问题 I can't get mocha working with Ember due to the fact that it fails when a test of the following nature is executed: describe('Location Panel', function () { beforeEach(function () { App.reset(); visit('/map/41.76721,-72.66907'); }); it('Have proper address', function () { var $title = find('.panel-header h2'); expect($title).to.have.text('476 Columbus Blvd, Hartford'); }); }); Basically it can't find any of the DOM elements, because it runs the test before the route has finished loading.. The

on applying toBeA() method on expect().toBe() it gives an error that cann't read the property of undefined

对着背影说爱祢 提交于 2020-01-05 09:13:15
问题 I am applying toBeA() method on expect() and it gives the error TypeError: Cannot read property 'toBeA' of undefined how can I apply these methods by chaining. utils.test.js code const expect = require('expect'); const utils = require('./utils'); it('should add two numbers',() => { var res = utils.add(44,11); expect(res).toBe(55).toBeA('number'); ----> here it gives the above error. }); it('Object should be equal',() => { expect([1,2,5,7]).toInclude(5); ---> here it gives the error TypeError:

Stubbing route callback render route status not found

♀尐吖头ヾ 提交于 2020-01-05 04:19:33
问题 I have a route app.get("/test", myControllers.controllerTest) The controllerTest returns current time as result to query my route test file describe.("GET /test", () => { it("should return correct response", done => { sinon.stub(myControllers, "controllerTest").yields(null, {time:'fake-time'}); app = require("../../server"); chai .request(app) .get("/test") .then(res => { expect(res.status).to.equal(200); expect(myControllers.controllerTest).to.have.been.calledOnce; done(); }) .catch(err=>{

import mocha unit tests result in sonarqube

自作多情 提交于 2020-01-04 14:14:58
问题 I use mocha to get unit tests results and istanbul to get code coverage. I'm using grunt to run these tasks. It works fine. I'm also using grunt-sonar-runner plugin to import these result in sonar. Currently code coverage is imported but that is not the case for unit tests results. During the build, sonar report me this : 20:40:19.410 WARN - Test result will not be saved for test class "Account Controllers User Controller forgot password", because SonarQube associated resource has not been

Mocha preserve file state in test

北城余情 提交于 2020-01-04 13:47:58
问题 I have a unit test that is testing updating of a config file... Of course after I run the test my file is now altered. I was thinking I could use "before" to cache the file and restore it on "after". mod = require('../modtotest'); describe('Device Configuration', function(){ var confPath = '../config/config.json'; var config; before(function(){ //cache object config = require(confPath); }) describe('Update Config', function(){ it('Should update config', function(done){ mod.updateConfig(); /

How do I write tests for an MQTT client?

天大地大妈咪最大 提交于 2020-01-04 07:25:12
问题 I'm new to MQTT and testing and am unsure how the two should work together. I'm using mqtt.js and want to write some basic tests. How should I structure them? More specifically, do I need to mock the MQTT broker, or can I make a live connection? Should that connection be to a test service like HiveMQ, etc, or to the broker I'm setting up myself? My setup: I'm building a chat application. 3 docker containers. 1 broker (using mosquitto, 2 clients. Clients are using mqtt.js within a script that