chai

Babel / Karma / Chai gives TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions

浪尽此生 提交于 2019-12-01 16:15:36
I having trouble figuring out why this test is not passing. var expect = require('chai').expect; describe('HelloComponent', function() { it('passes a quite simple test', function() { expect(1 + 4).to.equal(5); }); }); produces this error: DEBUG [web-server]: serving: /Users/ivan/dev/react-starter/node_modules/karma/static/context.html DEBUG [web-server]: serving (cached): /Users/ivan/dev/react-starter/node_modules/mocha/mocha.js DEBUG [web-server]: serving (cached): /Users/ivan/dev/react-starter/node_modules/karma-mocha/lib/adapter.js DEBUG [web-server]: serving (cached): /Users/ivan/dev/react

Chai assertion testing whether object structure contains at least other object structure

孤街浪徒 提交于 2019-12-01 05:18:47
I'm using Mocha for unit testing and Chai for assertions. I'd like to find an easy to use solution to check if an object has the structure and properties as defined in my comparison object. But I don't need the objects to be completely equal. The subject under test should contain at least all the properties in my test object, but it might also contain other properties which are not under test at that moment. So, I want to test a unit to check if the object it returns has at least a property named 'foo', which itself is an object that at least contains the property 'bar' with value 10. So, I

Installing Zombie.js Error: ReferenceError: Set is not defined. What am I doing wrong?

牧云@^-^@ 提交于 2019-12-01 03:14:56
Background: I'm currently reading " Web Development with Node and Express " by Ethan Brown (great book by the way for those learning node and express) and I got stuck on Chapter 5 - Quality Insurance. Everything was running smooth. First I ran the following: npm install --save-dev mocha npm install -g mocha npm install --save-dev chai npm install --save-dev zombie Problem: Then I ran (as the book instructed): mocha -u tdd -R spec qa/tests-crosspage.js 2>/dev/null But this wasn't doing anything. So then I ran: mocha -u tdd -R spec qa/tests-crosspage.js And then this error appeared: /Users

Chai assertion testing whether object structure contains at least other object structure

寵の児 提交于 2019-12-01 02:54:22
问题 I'm using Mocha for unit testing and Chai for assertions. I'd like to find an easy to use solution to check if an object has the structure and properties as defined in my comparison object. But I don't need the objects to be completely equal. The subject under test should contain at least all the properties in my test object, but it might also contain other properties which are not under test at that moment. So, I want to test a unit to check if the object it returns has at least a property

chai js expect property value empty array

狂风中的少年 提交于 2019-12-01 02:39:48
问题 I'm trying to write a unit test using chai js assertion, and was wondering how to expect arrays with zero length as values. My Test function expect statement: return expect(functionRetuningPromise()).to eventually.have.property("key1", []); Console Output on running mocha: AssertionError: expected { otherkey: otherVal, key1: [] } to have a property 'key1' of [], but got [] I have tried deep.property , key1:"[]" with no success 回答1: I ignored there's a section of change in assertion for

What is the difference between equal and eql in Chai Library

匆匆过客 提交于 2019-12-01 02:34:32
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. Strictly equal (or === ) means that your are comparing exactly the same object to itself: var myObj = { testProperty: 'testValue' }; var anotherReference = myObj; expect(myObj).to.equal(anotherReference); //

Installing Zombie.js Error: ReferenceError: Set is not defined. What am I doing wrong?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 23:27:25
问题 Background: I'm currently reading " Web Development with Node and Express " by Ethan Brown (great book by the way for those learning node and express) and I got stuck on Chapter 5 - Quality Insurance. Everything was running smooth. First I ran the following: npm install --save-dev mocha npm install -g mocha npm install --save-dev chai npm install --save-dev zombie Problem: Then I ran (as the book instructed): mocha -u tdd -R spec qa/tests-crosspage.js 2>/dev/null But this wasn't doing

Istanbul gives me coverage but ends output with an error

主宰稳场 提交于 2019-11-30 19:23:37
I'm testing out a simple application (from the Mocha tutorial code here https://marcofranssen.nl/using-mocha-chai-sinon-to-test-node-js/ ) to try to get Istanbul to work. My problem is that Istanbul works fine to give me a coverage summary, but then spits out an error for some reason and I'm not sure why. My tests all pass so they're hopefully not the problem. Here is how I run Istanbul: $ istanbul cover test.js ============================================================================= Writing coverage object [C:\Users\path\test\coverage\coverage.json] Writing coverage reports at [C:\Users

mocha, chai, Uncaught AssertionError: expected {} to equal {} + expected - actual [duplicate]

元气小坏坏 提交于 2019-11-30 18:04:10
This question already has an answer here: chai test array equality doesn't work as expected 3 answers it('GET /customers/ with wrong id', (done) => { request .get(`/customers/${wrongId}`) .end((err, res) => { expect(res.body).to.equals({}); expect(res).to.have.status(404); done(); }); }); 1) Customers CRUD GET /customers/ with wrong id: Uncaught AssertionError: expected {} to equal {} + expected - actual You want to use deep if you're trying to compare objects: expect(res.body).to.deep.equal({}); Or use the eql method: expect(res.body).to.eql({}); 来源: https://stackoverflow.com/questions

How does the expect().to.be.true work in Chai? [duplicate]

╄→гoц情女王★ 提交于 2019-11-30 17:06:36
This question already has an answer here: How does the chai expect function work? 2 answers expect(true).to.be.true; In this code, all the 'to', 'be', 'true' seems to be an attribute of the object response from 'expect(true)'. How can these attributes work so that they can raise an exception? You can check the source code: [ 'to', 'be', 'been' , 'is', 'and', 'has', 'have' , 'with', 'that', 'which', 'at' , 'of', 'same', 'but', 'does' ].forEach(function (chain) { Assertion.addProperty(chain); }); and there is a addProperty in utils : https://github.com/chaijs/chai/blob/master/lib/chai/utils