chai

Chai deep contains assertion on nested objects

纵然是瞬间 提交于 2019-12-23 09:44:08
问题 I'm trying to assert that a object contains another one(e.i. deep equal cannot be use), but it seems that the nested ones are checked strictly. Code example: describe('Meta', function () { it('object should contains a cloned copy', function () { var obj = {a: 1, b: '2', c: {a: 2, b: '2'}}; return expect(obj).deep.contains(JSON.parse(JSON.stringify(obj))); }); }); Error message: AssertionError: expected { a: 1, b: '2', c: { a: 2, b: '2' } } to have a property 'c' of { a: 2, b: '2' }, but got {

Formatting objects in chai.expect errors

…衆ロ難τιáo~ 提交于 2019-12-23 09:02:03
问题 When test fails, where I'm comparing two objects using expect(x).to.deep.equal(y) , I'd like to see the actual values in my browser test report. Instead, I see something like this: AssertionError: expected { Object (x, y, ...) } to deeply equal { Object (x, y, ...) } So it doesn't really show anything useful. Is there a way to customize how chai.js formats these objects? 回答1: You can now configure the max length before an object gets truncated as per the docs: chai.config.truncateThreshold =

Testing JavaScript Click Event with Sinon

心不动则不痛 提交于 2019-12-23 07:46:44
问题 I am trying to produce some test to be able to better understand how to test DOM events with the combination of Mocha, Chai, Sinon and jQuery. I want to check that the alert function is correctly triggered on a click of the div element. I know that the setup of the HTML element is correct jQuery, but I'm not entirely sure how to produce a passing test for the code below. What's particularly strange is that I get a dialogue appearing on opening the HTML file in my browser, so I know the line '

TypeScript: Could not find a declaration file for module in unit tests, only

北城余情 提交于 2019-12-23 04:16:07
问题 I'm using TypeScript with Visual Studio Code on Windows 10 to develop an NPM module. I use mocha/chai combined with nyc (istanbul) for unit testing and code coverage. For some of my tests I would like to use chai-bytes to compare buffers more easily. Unfortunately, there is no type definition file in the chai-bytes module and there is no definition at @types/chai-bytes available. Therefore, I have written my own type definition file for the chai-bytes plugin (which is very simple), but during

AssertionError: expected [ true ] to be true

巧了我就是萌 提交于 2019-12-22 14:00:32
问题 I have faced with the strange assertions problem so even successful assertions are marked as failed, like this: this.expect(this.getWidget('contacts').isNamesDisplayed()).to.eventually.be.true.and.notify(next); and in the console I have: 1 scenario (1 passed) 4 steps (4 passed) 0m03.618s [17:06:38] E/launcher - expected [ true ] to be true [17:06:38] E/launcher - AssertionError: expected [ true ] to be true As you see in this case test marked as successful despite of failed assertion, but in

Getting “is not a thenable” message while using “eventually” in protractor chai

我与影子孤独终老i 提交于 2019-12-22 11:24:02
问题 When I tried to verify the condition as below. var val1 = "ONE"; var val2 = "TWO"; expect(val1==val2).to.eventually.equal(false) I'm getting false is not a thenable message, If I removed eventually condition as below then it working fine. var val1 = "ONE"; var val2 = "TWO"; expect(val1==val2).to.equal(false) Can anyone help me to understand the difference. Also If the condition fails, It displays the error message and not executing the hooks.js . 回答1: In simple words: eventually - is a method

Mock a class method using mockery and sinon

爱⌒轻易说出口 提交于 2019-12-22 05:49:06
问题 I'm learning to unit test using the node module mockery with sinon. Using only mockery and a plain class I'm able to inject a mock successfully. However I would like to inject a sinon stub instead of a plain class but I'm having a lot of troubles with this. The class I am trying to mock: function LdapAuth(options) {} // The function that I want to mock. LdapAuth.prototype.authenticate = function (username, password, callback) {} And here is the code I'm currently using in my beforeEach()

Sinon - how to stub nested function?

橙三吉。 提交于 2019-12-21 05:06:41
问题 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

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

a 夏天 提交于 2019-12-20 17:39:17
问题 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? 回答1: 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}) 回答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

How to unit test a method of react component?

亡梦爱人 提交于 2019-12-20 08:48:18
问题 I am trying to unit test my reactjs component: import React from 'react'; import Modal from 'react-modal'; import store from '../../../store' import lodash from 'lodash' export class AddToOrder extends React.Component { constructor(props) { super(props); this.state = {checked: false} //debugger } checkBoxChecked() { return true } render() { console.log('testing=this.props.id',this.props.id ) return ( <div className="order"> <label> <input id={this.props.parent} checked={this.checkBoxChecked()