chai

Protractor Check if Element Does Not Exist

ε祈祈猫儿з 提交于 2019-12-03 10:36:56
问题 I have a setting in my angular based website that turns a dropdown on and off. If it is off, then it does not show on the main page. With Protractor, I need to check to see if this element is not present when the switch is off. However, I should not be thrown into Element Not Found Error, as it is one test in a set of many. How should I do this? I have tried to do: expect($$('.switch').count()).to.equal(0).and.notify(next); But I am getting an AssertionError with this... 回答1: Another option

Chai: expecting an error or not depending on a parameter [duplicate]

廉价感情. 提交于 2019-12-03 09:46:19
This question already has answers here : Mocha / Chai expect.to.throw not catching thrown errors (6 answers) I've been trying to do a text of a function that handles errors in a way that, if it is a valid error, it is thrown, but if it is not, then nothing is thrown. The problem is that i cant seem to set the parameter while using: expect(handleError).to.throw(Error); The ideal would be to use: expect(handleError(validError)).to.throw(Error); Is there any way to achieve this functionality? code of the function: function handleError (err) { if (err !== true) { switch (err) { case xxx: ... }

Testing for errors thrown in Mocha [duplicate]

笑着哭i 提交于 2019-12-03 09:16:46
This question already has answers here : Mocha / Chai expect.to.throw not catching thrown errors (6 answers) I'm hoping to find some help with this problem. I'm trying to write tests for an application I am writing. I have distilled the problem in to the following sample code. I want to test that an error was thrown. I'm using Testacular as a test runner with mocha as the framework and chai as the assertion library. The tests run, but the test fails because an error was thrown! Any help is greatly appreciated! function iThrowError() { throw new Error("Error thrown"); } var assert = chai.assert

How to test event emitters in node

 ̄綄美尐妖づ 提交于 2019-12-03 08:22:17
问题 Lets say I want to write this simple task. But I want to write a test validating that: This task emits object. Object has a property name. I'm testing with mocha and chai expect. Thanks in advance. I've tried every possible variant that came to mind, but could not come up with a solution. var util = require('util'), EventEmitter = require('events').EventEmitter; function SomeTask() { var self = this; setInterval(function() { self.emit('data', { name: 'name' }); }, 5000); } util.inherits

Protractor Check if Element Does Not Exist

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 05:23:38
I have a setting in my angular based website that turns a dropdown on and off. If it is off, then it does not show on the main page. With Protractor, I need to check to see if this element is not present when the switch is off. However, I should not be thrown into Element Not Found Error, as it is one test in a set of many. How should I do this? I have tried to do: expect($$('.switch').count()).to.equal(0).and.notify(next); But I am getting an AssertionError with this... Another option that worked a bit better for me, and uses protractor 'way' of doing things http://angular.github.io

Post request via Chai

半城伤御伤魂 提交于 2019-12-03 04:54:49
I am trying to make a request to my node JS server which accepts post/put call. The parameters I am trying to send with post call via chai is not visible on server (req.body.myparam). I have tried with below post request but ended with not results:- var host = "http://localhost:3000"; var path = "/myPath"; chai.request(host).post(path).field('myparam' , 'test').end(function(error, response, body) { and chai.request(host).post(path).send({'myparam' : 'test'}).end(function(error, response, body) { Node JS code is given below:- app.put ('/mypath', function(req, res){ //Handling post request to

How to unit test a method which connects to mongo, without actually connecting to mongo?

时光毁灭记忆、已成空白 提交于 2019-12-03 01:23:29
问题 I'm trying to write a test to test a method that connects to mongo, but I don't actually want to have to have mongo running and actually make a connection to it to have my tests pass successfully. Here's my current test which is successful when my mongo daemon is running. describe('with a valid mongo string parameter', function() { it('should return a rejected promise', function(done) { var con = mongoFactory.getConnection('mongodb://localhost:27017'); expect(con).to.be.fulfilled; done(); });

How to test event emitters in node

岁酱吖の 提交于 2019-12-02 22:07:16
Lets say I want to write this simple task. But I want to write a test validating that: This task emits object. Object has a property name. I'm testing with mocha and chai expect. Thanks in advance. I've tried every possible variant that came to mind, but could not come up with a solution. var util = require('util'), EventEmitter = require('events').EventEmitter; function SomeTask() { var self = this; setInterval(function() { self.emit('data', { name: 'name' }); }, 5000); } util.inherits(SomeTask, EventEmitter); module.exports = SomeTask; Here's an example using spies. https://github.com

Mocha Chai test case for angular configuration file

好久不见. 提交于 2019-12-02 19:51:12
问题 I am getting a hard time to resolve mocha chai test case for angular js configuration file . angular.module('myApp.myModule', []).config(function ($stateProvider, $urlRouterProvider) { $stateProvider.state('myModule', { url: '/myModule', templateUrl: function(){ return 'scripts/my-module/views/my-module.html'; }, controller: 'myModuleCtrl', controllerAs: 'myCtrl', css: 'styles/lazy-load/my-module.css' }); $urlRouterProvider.otherwise('/'); }) I need to cover mocha chai test case for return

chai: Cannot read property 'not' of undefined

最后都变了- 提交于 2019-12-02 18:55:10
问题 I am new to chai and mocha and I use the sample code for my first test case. Here is my code. var chai = require("chai"); var mocha = require("mocha"); var expect = chai.expect; describe("Test", function() { it("Test", function() { expect([1, 2]).to.be.an('array').that.does.not.include(3); }); }); I run mocha test.js The result is: TypeError: Cannot read property 'not' of undefined What is wrong with me? It seems .does return undefined. I remove .does and it works correctly. What is the