Tag: chai

JSON Stringify函数返回相等但chai的相等函数返回不相等

在一个使用chai“应该”断言的testing套件中,以下返回false: some.json.blob.should.equal(some.other.json.blob); 但是,这返回true: JSON.stringify(some.json.blob).should.equal(JSON.stringify(some.other.json.blob)); 我知道stringify()函数并不是testingJSON等价性的最稳健的方法,所以我想find一种直接比较JSON的方法,而不需要经过stringify。 如何直接比较对象而不使用JSON.stringify()?

怪异的断言与摩卡/柴和ES6诺言

我面对一个奇怪的行为与ES6承诺和一些摩卡/柴testing。 考虑下面的foo()函数返回一个promise,我想testing两件事情: 它返回一个承诺(所以,一个对象) 它会抛出一个exception(所以,一个对象)的失败。 问题是,下面的testingexpect(..).to.be.an('object')在这两种情况下失败,但types是 object (与typeof检查)。 这是我的代码: var chai = require('chai'); var expect = chai.expect; var foo = function (a, b) { return new Promise(function(resolve, reject) { if (a < b) { resolve(); } else { throw new Error('failed'); } }); } describe('foo function', function () { it('should return a promise', function () { […]

如何在调用时从spy.on(obj,'funcName')返回假数据?

我不知道有没有function! 请让我知道这有可能吗? 类似的东西: spy(obj, 'funcName').and.returnValue(5); // spy will return a fake data when 'funcName'called. 那么我正在使用mocha , chai-spies

如何使用文件参数进行摩卡/ chaitesting?

我有一个文件通常在命令行中运行 节点index.js myFile.bmp 我如何开始使用摩卡/ cha进行testing? TIA

不可变的柴断言错误虽然预期等于结果

我一直在使用节点/ redux,我有以下testing与柴: AssertionError: expected 'Map { "winos": List [ Map { "id": 1, "x": 1, "y": 1, "movable": false }, Map { "id": 2, "x": 2, "y": 2, "movable": false }, Map { "id": 5, "x": 5, "y": 5, "movable": false } ] }' to equal 'Map { "winos": List [ Map { "id": 1, […]

Nodejs / Express API简单的Mocha / Chaitesting

我正在尝试为我的API构build一个testing集,这个testing集是用nodejs / express和mocha / chai开发的。 基本上,索引返回一个简单的string,我知道它的工作原理,因为我可以在我的浏览器上看到: router.get('/', function(req, res, next) { res.send('Hello World from Eclipse'); }); 然后我按照这个教程来构build这个testing: var supertest = require("supertest"); var should = require("should"); // This agent refers to PORT where program is runninng. var server = supertest.agent("http://localhost:5000"); // UNIT test begin describe("SAMPLE unit test",function(){ // #1 should return home page it("should return home […]

我怎样才能将柴氏和柴氏结合起来?

我想写一个NodeJS chaitesting,它检查某个服务调用(这是一个数组)的结果是否包含一个与我所期望的相等的对象。 结果中可能会有更多的字段,我不想检查。 有两个柴的插件可以解决这个问题: chai-things (允许你使用像expect(i).to.include.something.that.deep.equals这样的语法)和chai-like (允许你使用像expect(i).to.be.like )的语法。 但是,它们并不起作用。 看到这个最小的工作示例: const chai = require('chai') const expect = chai.expect chai.use(require('chai-things')) chai.use(require('chai-like')) describe('the chai setup', function() { it('should work', function(done) { const i = [{ name: 'Name A', age: 1 }, { name: 'Name B', age: 2 }] // Works expect(i).to.include.something.that.deep.equals({ name: 'Name B', age: 2 }) […]

存根nodejs承诺在链中返回错误

我nodejs使用nodejs中的nodejs ,也是在testing它们。 我已经单独testing了各个模块,但是当涉及testingchain of promises ,我遇到了一些麻烦。 我尝试了下面的例子,在npm页面上find了sinon-as-promised的例子,但似乎没有设法控制stream程并触发链中第一个promise的错误。 我正在使用mocha , chai和sinon for作为我sinon的testing, sinon-as-promised和chai-as-promised 。 我试图testing这个模块: 'use strict'; var mySQS = require('./modules/sqs/sqs-manager'); var sWebHook = require('./modules/webhooks/shopify/webhooks'); var main = {}; main.manageShopifyWebhook = function (params, callback) { sWebHook.verify(params.srcHmac, params.rawBody, params.shopName.split('.myshopify.com')[0], params.productId) .then(function(data) { var body = { "params": { "productId": data.productId, "shopName": data.shopName }, "job": "call-update-item" }; mySQS.create_Queue(body) […]

Node.js – 摩卡done()方法在以前的testing中导致错误

我正在实现摩卡作为我的testing框架与柴我为Node.js写一个应用程序。 这个规范是为secureId.js写的。 // secureId.js "use strict" const bcrypt = require('bcrypt'); // Constructor for SecureID function SecureID(str, rounds, func) { // Makes salt and hash unable to be changed or viewed outside the member functions let hashedID; let gennedSalt; bcrypt.genSalt(rounds, (err, salt) => { gennedSalt = salt; bcrypt.hash(str, salt, (err, hash) => { hashedID = hash; […]

Immutablejs Map.update打破了unit testing

我试图拿起Redux和我下面的教程使用ImmutableJs。 我对ImmutableJs是完全陌生的,我只是想通过API文档去实现。 我的练习应用比教程复杂得多,所以我走了一段路,可能已经迷路了。 任何时候我使用Map.update()方法,我无法find一种方法来成功地testing我的代码。 这是我写的一个testing,试图找出什么是错的: import chai, {expect} from 'chai'; import chaiImmutable from 'chai-immutable'; import {List, Map} from 'immutable'; chai.use(chaiImmutable); describe("Immutable Test Issues", () => { it("should present accurate immutable equality", () => { // — Maps with Lists match just fine const a1 = Map({ test: 1, args: List([1, 2]) }); const a2 = […]