mocha

Mocha test case - are nested it( ) functions kosher?

ぐ巨炮叔叔 提交于 2019-12-21 09:16:49
问题 I have this case where I think I want to have nested it() test cases in a Mocha test. I am sure this is wrong, and I don't see any recommendations to do what I am doing, but I don't really know of a better way at the moment - basically, I have a "parent" test, and inside the parent test there's a forEach loop with all the "child" tests: it('[test] enrichment', function (done) { var self = this; async.each(self.tests, function (json, cb) { //it('[test] ' + path.basename(json), function (done)

How to retest same URL using Mocha and Nock?

荒凉一梦 提交于 2019-12-21 09:12:11
问题 Am using Mocha, Chai, Sinon, Proxyquire and Nock. For this particular test scenario (for which this question is being asked), wish to test the exact same URL several times, each in a separate test that expects a different response. For example, a response with no merchant feeds, 1 merchant feed, and yet again with 2 merchant feeds. The existing code all works, furthermore if I run tests individually they pass. However, if i run them together using Mocha in a single suite they fail. Believe

Expect assertions type error -> expect(…).toExist is not a function

谁都会走 提交于 2019-12-21 08:26:07
问题 I'm testing a nodejs app. Where I find this error when I run the test. The test script is below: .expect( (res) => { expect(res.headers['x-auth']).toExist(); expect(res.body._id).toExist(); expect(res.body.email).toBe(email); }) the error showed: TypeError: expect(...).toExist is not a function how can I resolve this issue?? TIA. 回答1: The expect assertion library has changed ownership. It was handed over to the Jest team, who in their infinite wisdom, created a new API. You must now use

how to pass compiler options to mocha

江枫思渺然 提交于 2019-12-21 07:28:39
问题 I run a mocha command to run my tests $ ./node_modules/.bin/mocha --compilers coffee:coffee-script -R spec I wish to pass additional options to the coffee-script compiler (--bare to avoid the outer closure that is introduced when compiling .coffee to .js). Is there a way to do this? I tried $ ./node_modules/.bin/mocha --compilers coffee:coffee-script --bare -R spec but that doesn't look right. It also failed saying that --bare is not a valid option for mocha. error: unknown option `--bare'

Running a set of actions before every test-file in mocha

南笙酒味 提交于 2019-12-21 07:08:59
问题 I've started recently working with mocha to test my expressjs server. My tests are separated to multiple files and most of them contain some duplicated segments (Mostly before statements that load all the fixtures to the DB, etc) and that's really annoying. I guess I could export them all to a single file and import them on each and every test, but I wonder if there are some more elegant solutions - such as running a certain file that has all the setup commands , and another file that

Is there a way to undo Mocha stubbing of any_instance in Test::Unit

时光总嘲笑我的痴心妄想 提交于 2019-12-21 06:49:27
问题 Much like this question, I too am using Ryan Bates's nifty_scaffold. It has the desirable aspect of using Mocha's any_instance method to force an "invalid" state in model objects buried behind the controller. Unlike the question I linked to, I'm not using RSpec, but Test::Unit. That means that the two RSpec-centric solutions there won't work for me. Is there a general (ie: works with Test::Unit) way to remove the any_instance stubbing? I believe that it's causing a bug in my tests, and I'd

A simple WebdriverIO - Mocha test doesn't display browser

喜你入骨 提交于 2019-12-21 06:23:39
问题 I want to test NOT headlessly but I cannot do that. The below code start chrome browser . NOT headless . OK. // test.js var webdriverio = require('webdriverio'); var options = { desiredCapabilities: { browserName: 'chrome' } }; webdriverio .remote(options) .init() .url('http://www.google.com') .title(function(err, res) { console.log('Title was: ' + res.value); }) .end(); The below code ( Mocha test code) doesn't start chrome browser by $ mocha test.js . Headless . NG. But the test pass! I

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

How can I get Mocha's Unicode output to display properly in a Windows console?

天大地大妈咪最大 提交于 2019-12-21 04:06:59
问题 When I run Mocha, it tries to show a check mark or an X for a passing or a failing test run, respectively. I've seen great-looking screenshots of Mocha's output. But those screenshots were all taken on Macs or Linux. In a console window on Windows, these characters both show up as a nondescript empty-box character, the classic "huh?" glyph: If I highlight the text in the console window and copy it to the clipboard, I do see actual Unicode characters; I can paste the fancy characters into a

NodeJS supertest access to session object

余生颓废 提交于 2019-12-21 03:58:12
问题 I'm testing my Node.js application with supertest. In my controller I access the session object. In order to make a valid request this session object needs to be filled with some data. Controller // determine whether it is user's own profile or not var ownProfile = userId == req.session.user._id ? true : false; Test it('profile', function (done) { testUserOne.save(function(error, user){ request .agent(server) .get('/profile?userId=' + user._id) .expect('Content-Type', /html/) .expect(200)