chai

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

自闭症网瘾萝莉.ら 提交于 2019-12-04 16:36:20
问题 This question already has answers here : Mocha / Chai expect.to.throw not catching thrown errors (6 answers) Closed 2 years ago . 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

Testing for errors thrown in Mocha [duplicate]

强颜欢笑 提交于 2019-12-04 14:54:56
问题 This question already has answers here : Mocha / Chai expect.to.throw not catching thrown errors (6 answers) Closed 2 years ago . 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

Mocha and Chai test fails when testing function with setInterval

主宰稳场 提交于 2019-12-04 14:35:06
I'm new to TDD and working with Mocha and Chai. I have created a test that passes when a value is increased, but when that increase is put within a setInterval, it fails. The objective of this code is to have something move across the screen. function startMovingThing(){ var position = setInterval(function() { moveThing(10); }, 100); } function moveThing(number){ thing.position += number; thingOnScreen.style.left = thing.position + 'px'; } test: describe('Thing', function() { it('should increase position', function(){ assert.increases(startMovingThing, thing, 'position'); }); }); How can I get

accessing variables from executescript function

六月ゝ 毕业季﹏ 提交于 2019-12-04 13:20:55
I'm looking to set some data dynamically during testing using browser.executescript. Something like: var x; browser.executeScript(function () { var something = x; }); But x seems to be out of the scope of the function being run. Is there a way for me to pass arguments that will be in the inner scope? Any help greatly appreciated C Pass the arguments inside arguments : Any arguments provided in addition to the script will be included as script arguments and may be referenced using the arguments object. Arguments may be a boolean, number, string, or webdriver.WebElement. Arrays and objects may

NightmareJS multiple evaluations

泪湿孤枕 提交于 2019-12-04 05:43:06
NightmareJS works great when I am running one evaluation, but as I interact with the page I need to do more evaluations as things pass. However using the docs I tried a simple sample of chaining evaluations and I get an error: describe('test google search results', function() { this.timeout(15000); it('should find the nightmare github link first', function(done) { var nightmare = Nightmare({show: true}) nightmare .goto('http://google.com') .wait(1000) .type('form[action*="/search"] [name=q]', 'github nightmare') .click('form[action*="/search"] [type=submit]') .wait(1000)//.wait('#rcnt')

What is the difference between equal and eql in Chai Library

好久不见. 提交于 2019-12-03 23:39:34
问题 I'm pretty new to Javascript, and I have a quick question regarding the Chai library for making unit tests. When I was studying some materials on the Chai library, I saw a statement saying equal "Asserts that the target is strictly equal (===) to value" and eql "Asserts that the target is deeply equal to value.". But I'm confused about what the difference is between strictly and deeply. 回答1: Strictly equal (or === ) means that your are comparing exactly the same object to itself: var myObj =

Sinon - how to stub nested function?

一笑奈何 提交于 2019-12-03 16:00:21
Apologies if this is a simple question, I'm relatively new to Node and Sinon. I'm struggling trying to figure out how to assert that a nested asynchronous function was called in Nodejs. I'm using mocha, chai, sinon, and request ( https://github.com/request/request ) but think I'm missing something basic on the stubbing part. Example inside my_app.js - var request = require('request'); function MyModule() { }; MyModule.prototype.getTicker = function(callback) { request('http://example.com/api/ticker', function(error, response) { if (error) { callback(error); } else { callback(null, response); }

Post request via Chai

点点圈 提交于 2019-12-03 15:14:17
问题 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

Verify that an exception is thrown using Mocha / Chai and async/await

主宰稳场 提交于 2019-12-03 11:56:06
问题 I'm struggling to work out the best way to verify that a promise is rejected in a Mocha test while using async/await. Here's an example that works, but I dislike that should.be.rejectedWith returns a promise that needs to be returned from the test function to be evaluated properly. Using async/await removes this requirement for testing values (as I do for the result of wins() below), and I feel that it is likely that I will forget the return statement at some point, in which case the test

Mocha, Chai: Assert that Object is included in an Array of Objects

前提是你 提交于 2019-12-03 10:40:23
Chai has a nice way to assert if an Array includes a certain element expect([1,2,3]).to.include(2); What I would like is something similar, given an Array of Objects: expect([{a:1},{b:2}]).to.include({b:2}); Is this possible? Take a look at the Chai Things plugin , that does what you want: [{a:1},{b:2}].should.include.something.that.deep.equals({b:2}) Here is an alternative and non order dependent approach for collections: array expect([1, 2, 3]).to.include.members([3, 2, 1]) You can also use this with a deep flag for comparison of objects: array of objects expect([{ id: 1 }]).to.deep.include