chai

Can't get chai.spy.on to work

℡╲_俬逩灬. 提交于 2021-02-08 05:36:17
问题 Please don't suggest to use Sinon. I want to get chai-spies specifically chai.spy.on working with your help. Basically, I have this spec. Inside my initialize method in PatientController, I call this.initializePatientEvents(); beforeEach(function() { this.patientController = new PatientController({model: new Backbone.Model(PatientModel)}); }); it('executes this.initializePatientEvents', function () { let spy = chai.spy.on(this.patientController, 'initializePatientEvents'); expect(spy).to.have

Importing Chai in Typescript

房东的猫 提交于 2021-02-07 13:16:02
问题 I'm trying to use chai in typescript. Chai's javascript example shows this as: var should = require('chai').should(); I downloaded the type definition: tsd install chai ...referenced the file, tried to import /// <reference path='../typings/chai/chai.d.ts' /> import should = require('chai').should(); I get: error TS1005: ';' expected ...any idea how to do this? 回答1: The tests for the chai typings do the following: import chai = require('chai'); var should = chai.should(); Does that work for

使用 TypeScript 和依赖注入实现一个聊天机器人[每日前端夜话0x76]

痞子三分冷 提交于 2021-02-03 12:38:12
使用 TypeScript 和依赖注入实现一个聊天机器人[每日前端夜话0x76] 疯狂的技术宅 前端先锋 每日前端夜话0x76 每日前端夜话,陪你聊前端。 每天晚上18:00准时推送。 正文共:3509 字 预计阅读时间: 10 分钟 翻译:疯狂的技术宅 来源:toptal 类型和可测试代码是避免错误的两种最有效方法,尤其是代码随会时间而变化。我们可以分别通过利用 TypeScript 和依赖注入(DI)将这两种技术应用于JavaScript开发。 在本 TypeScript 教程中,除编译以外,我们不会直接介绍 TypeScript 的基础知识。相反,我们将会演示 TypeScript 最佳实践,因为我们将介绍如何从头开始制作 Discord bot、连接测试和 DI,以及创建示例服务。我们将会使用: Node.js TypeScript Discord.js,Discord API的包装器 InversifyJS,一个依赖注入框架 测试库:Mocha,Chai和ts-mockito Mongoose和MongoDB,以编写集成测试 设置 Node.js 项目 首先,让我们创建一个名为 typescript-bot 的新目录。然后输入并通过运行以下命令创建一个新的 Node.js 项目: 1npm init 注意:你也可以用 yarn,但为了简洁起见,我们用了 npm。

Test simple logger functions with full code coverage

…衆ロ難τιáo~ 提交于 2021-01-29 14:33:35
问题 I'm using Chai, Sinon and Instanbul to test a NodeJS application. Here's the Logger code: import Debug, { IDebugger } from 'debug'; export default class Logger { private readonly dbg: IDebugger; constructor(name: string) { this.dbg = Debug(name); } public log(str: string): void { this.dbg(str); } } Here's the test that I have built to start with: import * as fs from 'fs'; import sinon from 'sinon'; import { expect } from 'chai'; import Logger from '../../src/utils/Logger'; import Debug from

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

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

史上最全软件开发|程序员必备的工具集

瘦欲@ 提交于 2021-01-11 15:23:38
史上最全软件开发|程序员必备的工具集 软件开发程序员在整个产品研发的过程中起着很重要的作用, 由于经常研究各种技术,他不会精确记得所有语言代码的语法和API,他觉得没有Google和百度,几乎没法工作。他记的只是一个Key,一个如何找寻答案的索引,而不是全部 。正所谓 “工欲善其事必先利其器”我们程序员也是一样,选择一个好工具可以大大提升开发效率,下面是我使用的一些并且觉得很不错的软件,和大家分享下。 最后还会给大家介绍一款我最近在 测试全流程一站式的测试神器。 一、办公类: 软件开发工程师常用工具: 1.1、OneNote: https://www.onenote.com/download/ 微软office自带的一款类似笔记本的软件,我一般所有的学习笔记都是放在上面的,跟有道云笔记类似,推荐使用,华为研发人员大多都是用这个,谁用谁知道 1.2、Teamviewer:这是一款非常好用的多人回忆演示等集一体的软件,类似于华为内部使用的Espace软件 1.3、腾讯文档: https://docs.qq.com/desktop 1.4、Processon免费作图: https://www.processon.com/ 二、研发类: 2.1、Github: https://github.com/ 适合团队开发人员之间共同开发时使用 2.2、SVN: https:/

How to send Headers ('Authorization','Bearer token') in Mocha Test cases

别说谁变了你拦得住时间么 提交于 2021-01-05 04:27:15
问题 I am writing a test case to test my API . When I try to test for any open API, it is working fine. But When I try to send Authorization Token along with my API, it is not working. Here is the code: The way i am sending headers is: .set("Authorization", "Bearer " + token) Is it the correct way of sending? I have tried to send the Authorization token in Auth. But not able to get the same. But when I tried to consume same in Postman, it is working fine. it("Get some random Info", function(done)

How to send Headers ('Authorization','Bearer token') in Mocha Test cases

血红的双手。 提交于 2021-01-05 04:25:32
问题 I am writing a test case to test my API . When I try to test for any open API, it is working fine. But When I try to send Authorization Token along with my API, it is not working. Here is the code: The way i am sending headers is: .set("Authorization", "Bearer " + token) Is it the correct way of sending? I have tried to send the Authorization token in Auth. But not able to get the same. But when I tried to consume same in Postman, it is working fine. it("Get some random Info", function(done)