mocha

Mocha with Azure Mobile App: Getting Started

十年热恋 提交于 2020-01-24 20:05:26
问题 tl;dr; Because of the close vote, I wanted to clarify what I'm asking. I want to know how to go from a functional, local Azure Mobile App with a Node.js backend to one that can be tested successfully with Mocha and Chai. The 3 issues listed below are all hurdles that I see that are keeping me from testing my App Service in this way. There seems to be something extra that is required that makes an Azure App Service different from a standard Node.js web application. I am trying to figure out

simple example of electron app with spectron test

北战南征 提交于 2020-01-24 19:34:37
问题 I am trying to learn how to test apps, build with electron, using spectron. for this I took an example application from the web with a simple header, counter label, and incrementer button. I use mocha as a test runnen. The test should launch the app, push the button and check the counter label. I can't even get to the point where the app is launched properly. I am getting the error " TypeError: Cannot read property 'waitUntilWindowLoaded' of undefined" when I run the test. Also when looking

How Mocha knows which file to load first in the test suite

烈酒焚心 提交于 2020-01-22 19:53:11
问题 I'm trying to learn the A Test Driven Approach with MongodB. The folder structure A user.js to test in the src folder const mongoose = require('mongoose'); mongoose.Promise = require('bluebird'); const Schema = mongoose.Schema; const UserSchema = new Schema ({ name: String }); const User = mongoose.model('user', UserSchema); module.exports = User; Content of test_helper.js const mongoose = require('mongoose');; mongoose.connect('mongodb://localhost/users_test'); mongoose.connection .once(

Test in loop mocha

强颜欢笑 提交于 2020-01-21 11:09:24
问题 I am trying to use data provider in mocha to write less code var should = require('should'); var assert = require('assert'); var request = require('supertest'); var mongoose = require('mongoose'); var winston = require('winston'); var config = require('../app/config'); describe('Authentification', function() { var url = config.web.protocol + '://' + config.web.host + ':' + config.web.port; describe('signin',function() { var provider = [ { describe: 'should return error trying to signin with

Test in loop mocha

好久不见. 提交于 2020-01-21 11:09:15
问题 I am trying to use data provider in mocha to write less code var should = require('should'); var assert = require('assert'); var request = require('supertest'); var mongoose = require('mongoose'); var winston = require('winston'); var config = require('../app/config'); describe('Authentification', function() { var url = config.web.protocol + '://' + config.web.host + ':' + config.web.port; describe('signin',function() { var provider = [ { describe: 'should return error trying to signin with

npm基础入门

泪湿孤枕 提交于 2020-01-20 13:58:51
1. npm简介 先来看下官方介绍: npm makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you’re sharing 大概的意思就是: npm 是一个包管理器,让 JavaScript 开发者分享、复用、更新代码更方便。 npm有两层含义:一层含义是Node的开放式模块登记和管理系统(存包系统),网址:https://www.npmjs.com/;另一层含义是Node默认的模块管理器,是一个命令行软件,可以用来安装、管理和发布Node模块。 我们考虑下,没有npm之前前端程序员的操作方式: 当项目需要jQuery,需要手动去 jQuery 官网下载 jQuery 当项目需要BootStrap ,手动去 BootStrap 官网下载 BootStrap 当项目需要Underscore ,手动去 Underscore 官网下载 Underscore ....... 当有了npm之后,这些事情都不需要我们手动去处理了,npm自动去帮我们处理,其主要思想就是使用npm来把这些代码集中到一起来管理。 买个服务器作为代码仓库(repository,也就是:https://www.npmjs.com/)

ts+react, 用mocha测试setInterval,

为君一笑 提交于 2020-01-17 13:54:56
Question 如何用mocha测试setInterval, 在代码中,将setInterval和clearInterval放在一个函数中,并且用一个公共属性public或private属性来赋值,测试的时候会报错 原因 mocha测试主要是node环境,所以找不到windows对象下的时间 解决方案 先修改开发代码 用组件state来赋值,将setInterval单独放入一个函数,clearInterval单独放入一个函数 /** * #### Starts the timer and update the component's state * @param autoRefreshTimeS is equal component's state interval (s) * ***** * ### Attention: * this is asynchronous operations */ private startTimer(autoRefreshTimeS: number) { this.state.logger.debug("Starting timer with interval", autoRefreshTimeS); let second = 0; const timer = setInterval(async () => { this.state.logger

Cannot able to access dynamic test values inside “it” function of mocha, though it is accessible inside “describe” function

99封情书 提交于 2020-01-17 04:50:06
问题 I was able to access dynamic values inside describe exactly but not inside it block. (mostly I am getting last value of the array) for( var i =0 ;i< dynamicValues.length; i++){ (function wrap(dynamicValue){ describe("condition", function(){ // It is logging correct value. console.log(dynamicValue) it("should be accessible", function(){ // It is not logging correct value, but logging last value of array. console.log(dynamicValue); } }) }(dynamicValues[i])); } How to get same "environment" of

蛋疼的mocha库-promise异步测试

被刻印的时光 ゝ 提交于 2020-01-17 02:27:29
mocha 测试库的使用 错误的处理异步测试 异步当出现断言错误的时候,他会抛出错误,但不会把这次测试当作失败,就是正确的顺利通过测试了,很无语。 promise的reject会在then的第二个函数内处理,当遇到unhand的错误时,catch会进行处理,在then的函数内部出现运行错误,也会跳转到catch进行处理,相当于trycatch。如果不指定then的第二个函数,就会跳转到catch处理,catch中出现错误,就会出现unhand的错误,直接报错。自己想想 或许是只有异步才会出现下列情况 describe('测试全部resolve', () => {// 在这里传入done,对不去,里面不能使用done it("返回['success1', 'success2']", (done) => {// 在这里传入done,确实可以使用done,但是只有断言错误,才会触发,如果断言正确,就会卡死,出现超时。 promiseAll([ delay(100, 'success1'), delay(50, 'success2'), ]).then((res) => { assert.deepEqual(res, ['success2', 'success1']); }, (err) => { done(err); }) }).catch((err) => { done(err) })

Mocha Tests Running Before Docs Defined in Before Block Are Done

别说谁变了你拦得住时间么 提交于 2020-01-16 11:26:27
问题 I am creating some mocha tests for my Node app. In my test, before retrieving some docs that are created, I need to first create those docs in the database. Then I retrieve them and run some tests on the results. The problem I'm noticing is that even though I've included the function that needs to run to create the docs in the first before() block, and even though I'm awaiting the result of the doc creation function, my tests run BEFORE the docs are finished being created. It seems the before