mocha

Trouble displaying test results in browser with Mocha, Chai, and webdriver.io

二次信任 提交于 2020-02-06 08:04:07
问题 I am using Webdriver.io with Mocha and Chai. I've written several tests that work great from the command line. It opens the Chrome browser, runs the tests, and displays the resultsin the command line. However I am having issues getting the results of the tests to display in the browser view (have a presentation that I would like to show the tests in the browser view). I'm using the mocha html template for viewing tests in the browser, but it only displays "passes: 0failures: 0duration: 0s" in

nyc (istanbul) exclude test code from coverage reports

陌路散爱 提交于 2020-02-03 10:10:50
问题 I'm trying to add coverage report generation to a typescript library project. The layout includes these directories: project ├─ src │ ├─ lib ## project code (typescript), *.tsx │ ├─ test ## test specs (typescript), *.spec.tsx │ └─ @types ## types I made for a few dependencies that didn't have them └─ build ├─ lib ## compiled project code (ES5 + type info, with inline sourcemaps), *.js and *.d.ts └─ test ## compiled test specs (ES5 + type info, with inline sourcemaps), *.spec.js and *.spec.d

设计模式3——装饰者模式

左心房为你撑大大i 提交于 2020-02-03 08:59:34
定义:动态的将责任附加到对象上。若要扩展功能,装饰者提供了比继承更加弹性的解决方案。 1 引例_咖啡订单系统 1.1 最初设计。 如图1,首先创建一个Bevarage(饮料)的抽象类,店内所有的咖啡都继承这个类。description是成员变量,由子类设置,描述咖啡使用。 getDescription() 就是返回这个描述。 cost() 方法是抽象方法,由子类实现,计算价格使用。 最开始咖啡就有如下4个(对咖啡不太了解,中文名字错了不要在意):DarkRoast(超优深焙咖啡),Espresso(浓缩咖啡),Decaf(低卡咖啡),HouseBlend(混合咖啡) 但客人要求在咖啡里添加调料:Milk(奶),Soy(豆浆),Mocha(摩卡),每种调料都有单独的价钱,所以设计上又添加了这些,如图2。 这里我们可以看出问题,图2中只是列出了三种组合,我们可以想一下,这种组合是由很多种的,现在是4款咖啡,3种调料,在考虑到以后,可定会推出更多的咖啡和各种调料。这样维护起来,类会爆炸的,而且有的人还喜欢double份的Mocha,这样算的话类就会无穷无尽,而且物价是波动的,你还会修改价格,这样维护起来会死人的。 1.2 进一步改进 如图3,这次将调料加入 Bevarage 中的成员变量中,并加入相应的has和set方法, cost() 方法现在提供实现,计算出调料的价格

nodejs之包教不包会

五迷三道 提交于 2020-01-28 09:45:11
  今天在lesson6的时候,遇到了一个mocha的测试框架,当将代码写好之后,全局安装,项目安装mocha,命令行运行mocha,输出“mocha 不是内部或外部命令”。作者是这样写的”装个全局的 mocha: $ npm install mocha -g 。“” -g 与 非 -g 的区别,就是安装位置的区别,g 是 global 的意思。如果不加的话,则安装 mocha 在你的项目目录下面;如果加了,则这个 mocha 是安装在全局的,如果 mocha 有可执行命令的话,那么这个命令也会自动加入到你系统 $PATH 中的某个地方(在我的系统中,是这里 /Users/alsotang/.nvm/v0.10.29/bin )“;(mac本;)   现在的状态是 卸载了nvm,重新安装了node稳定版。但是在npm i mocha -g 的时候,自动生成了node_nvm,存放在D:\web-software\node_nvm\nvm\npm\node_modules\mocha\bin\mocha这个目录。   说说其他的lesson,lesson7还是mocha,lesson8是supertest依旧是测试用例,也用到了mocha,should;lesson9正则表达式,teacher曾说正则是有一个专门的人去写的,真的吗?什么公司?还是要有一些基础知识的。 lesson10

Schema hasn't been registered for model “categories”. Use mongoose.model(name, schema)

老子叫甜甜 提交于 2020-01-25 21:13:27
问题 When i called my function in controller through postman,it worked fine and i got results but when i wrote a test case for the same function it is saying the error as MissingSchemaError: Schema hasn't been registered for model "categories". Use mongoose.model(name, schema) I was completely confused about these because how come a function that is working well go wrong with test case.Can any one suggest help please. My test.js, var server = require('../modules/categories/model/categories.server

supertest expect(function(res){}) , Error: expected [Function] response body ??

孤者浪人 提交于 2020-01-25 12:02:08
问题 I'm using supertest and mocha testing my express rest api. there's this test case I want to check the returned response body with a method of supertest:expect(function(res){ } ). But I'm facing an error that I can't figure out why: Error: expected [Function] response body, got '{"name":"Aaron Shen","_id":" 530ed1ce92788ed031022d8c","__v":0,"active":true}' Does anybody know how to fix? below is my testing code: it('should return correct player',function(done){ var url = '/api/players/' + pid;

supertest expect(function(res){}) , Error: expected [Function] response body ??

自作多情 提交于 2020-01-25 12:01:05
问题 I'm using supertest and mocha testing my express rest api. there's this test case I want to check the returned response body with a method of supertest:expect(function(res){ } ). But I'm facing an error that I can't figure out why: Error: expected [Function] response body, got '{"name":"Aaron Shen","_id":" 530ed1ce92788ed031022d8c","__v":0,"active":true}' Does anybody know how to fix? below is my testing code: it('should return correct player',function(done){ var url = '/api/players/' + pid;

How to check in the teardown method of mocha (tdd) if the current test failed?

淺唱寂寞╮ 提交于 2020-01-25 08:22:08
问题 I know how to check if a test failed in the afterEach() method of mocha: That's explained here: detecting test failures from within afterEach hooks in Mocha But what about the people using suite and test (tdd) instead of describe and it ?? How can I check if the current test failed here? The same code won't work because state would be undefined: teardown(async () => { // check if failed: if (this.currentTest.state === 'failed') { console.log("fail"); } }); 回答1: It seems that it works a little

Catching Mocha timeouts

落爺英雄遲暮 提交于 2020-01-25 04:12:45
问题 I'm writing a node.js web service which needs to communicate with another server. So its basically server to server communication. I don't have any previous experience of writing web services so I have very limited knowledge. For unit tests I'm using Mocha. Now, I intend to test the behavior of my service for a particular scenario when this other server doesn't respond to my GET request and the request is actually timed out. For tests I've created a fake client and server around my web

How to isolate and iterate over individual React components in a React application

谁说我不能喝 提交于 2020-01-25 01:44:32
问题 React hot loading is very nice. There are some React components that are mounted after some user interaction. I want to implement these components separated from the application. I don't want to separate them as different npm modules though. I just want to mount them to the landing page and implement. This is like having a test runner that runs each component separately not for testing, but for implementing it live (changing css etc.). Is this possible somehow? 回答1: You're describing