mocha

Full Gulp Istanbul Coverage Report

不羁岁月 提交于 2019-12-21 03:33:36
问题 I am using gulp-istanbul to generate JavaScript unit test coverage reports through Gulp. Is there a way to configure Istanbul to generate a full coverage report of all the JS files in my gulp stream, and not just the files touched by a test case. I'm working on a project with a lot of JS, but no unit tests, and we are trying to increase the test coverage. I would like to have a coverage report that starts by show 0% coverage for most of our files, but over time will present an increasing

Simple protractor test for isElementPresent failing with unsupported locator strategy

空扰寡人 提交于 2019-12-21 01:40:08
问题 My test: it('should allow login', function() { browser.get('index.html'); $('#username').sendKeys('administrator'); $('#password').sendKeys('password'); $('#login').click(); var logout = $('#logout'); expect($p.isElementPresent(logout)).to.eventually.be.true; }); But this errors out with: Error: Unsupported locator strategy: click at Error (<anonymous>) at Function.webdriver.Locator.createFromObj (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/locators.js

Asserting files that have the same content

≯℡__Kan透↙ 提交于 2019-12-20 19:05:29
问题 I am using mocha/supertest/should.js to test my Rest Service GET /files/<hash> returns file as stream. How can I assert in should.js that file contents are the same? it('should return file as stream', function (done) { var writeStream = fs.createWriteStream('test/fixtures/tmp.json'); var req = api.get('/files/676dfg1430af3595'); req.on('end', function(){ var tmpBuf = fs.readFileSync('test/fixtures/tmp.json'); var testBuf = fs.readFileSync('test/fixtures/test.json'); // How to assert with

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

Read response output buffer/stream with supertest/superagent on node.js server

廉价感情. 提交于 2019-12-20 11:32:07
问题 I am trying to write a test that checks whether an API route outputs a ZIP file with the correct contents. I am using mocha and supertest for testing, and I would like to actually read the output stream/buffer, read the zip file contents and see if the contents are correct. Any ideas how should I do it? When I try to read res.body , it's just an empty object. request(app) .get( "/api/v1/orders/download?id[]=1&id=2" ) .set( "Authorization", authData ) .expect( 200 ) .expect( 'Content-Type',

Run node inspector with mocha

我的梦境 提交于 2019-12-20 09:55:41
问题 I can't seem to debug mocha scripts. I am able to run node with inspector like this node --inspect script.js . This then gives me a url to go to to debug, something like chrome-devtools://devtools/remote/... However, when I use mocha with this line mocha --inspect test.js I am not able to debug. It says 'Debugger listening on [::]:5858'. Is there any way for me to debug a mocha test using node's inspector? Going to localhost:5858 gives me this info: Type: connect V8-Version: 5.1.281.84

nodejs mocha suite is not defined error

时光总嘲笑我的痴心妄想 提交于 2019-12-20 09:51:09
问题 I am trying to run some tests using mocha but cant seem to get over this error. E:\tdd\nodejs\cart>mocha cart.test.js node.js:201 throw e; // process.nextTick error, or 'err ^ ReferenceError: suite is not defined at Object.<anonymous> (E:\tdd\nodejs\cart\cart.test.js:5:1 at Module._compile (module.js:432:26) at Object..js (module.js:450:10) at Module.load (module.js:351:31) at Function._load (module.js:310:12) at Module.require (module.js:357:17) at require (module.js:368:17) at C:\Users\lex

how can I subscribe to mocha suite events?

陌路散爱 提交于 2019-12-20 09:04:10
问题 I'd like to be able to extend the mocha test results and listen to them from the available mocha object. First, I'm looking at getting the "passes" results. It looks like they might be subscribed to from suite but I'm not sure how... I've tried the following which I thought would listen to the end of all of my tests: var suite = mocha.suite.suites[0]; suite.on("end", function(e){ console.log(e, "mocha - heard the end of my test suite"); } ); My simple hack which works but isn't elegant at all

What is the difference between assert, expect and should in Chai?

…衆ロ難τιáo~ 提交于 2019-12-20 08:01:55
问题 What is the difference between assert , expect and should , and when to use what? assert.equal(3, '3', '== coerces values to strings'); var foo = 'bar'; expect(foo).to.equal('bar'); foo.should.equal('bar'); 回答1: The differences are documented there. The three interfaces present different styles of performing assertions. Ultimately, they perform the same task. Some users prefer one style over the other. This being said, there are also a couple technical considerations worth highlighting: The

Mocha testing inside async callbacks

老子叫甜甜 提交于 2019-12-20 04:57:16
问题 I have simplified the example to be able to explain it well. I have an array which I want to iterate on. For each element of the array I want to execute a test with async/await functions, so I have this code: const chai = require('chai'); const expect = chai.expect; describe('Each film', async() => { await Promise.all([1, 2, 3].map(async(n) => { await new Promise(resolve => setTimeout(() => resolve(), 1000)); console.log('N:', n); it('test', async() => { expect(true).to.be.true; }); })); });