mocha

How to assert not null?

女生的网名这么多〃 提交于 2020-01-01 07:26:09
问题 I'm very new in javascript testing, I would like to know how to assert not null in Mocha framework. 回答1: Mocha supports any assertion library you want. You can take a look at how it deals with assertions here: http://mochajs.org/#assertions. I don't know which one you want to use. Considering you are using Chai, which is pretty popular, here are some options: Consider "foo" to be the target variable you want to test Assert var assert = chai.assert; assert(foo) // will pass for any truthy

How to I configure TeamCity build with Mocha?

北城余情 提交于 2020-01-01 02:51:09
问题 I have a project that I am setting up through teamcity for CI. The project itself is a nodejs application and it includes test written in mocha, which we cover through jscoverage. In the build configuration I'm setting up I have 3 build steps which occur on checkin. call jscoverage.exe against the folders in my project that I'm covering. call mocha to run the test against the jscovered files from step 1 and output to the html-cov reporter move the generated coverage.html report into a public

why mocha in browser throw global leak detected from a url but not from a unc path?

依然范特西╮ 提交于 2020-01-01 02:47:25
问题 I'm creating a javascript library and want to use BDD, so I'm giving a try at mocha and I can't make it work. I want that library to be used on the client, so I'm assuming that it make sense to have it running from a browsable url, to be in a context of web connection, and not just a sandbox from a unc path. here is the dummy starting point file test/test.foobar.js var assert = chai.assert; var foobar = { sayHello: function() { return 'Hello World!'; } }; describe('Foobar', function() {

Running Mocha tests compiled with Babel in Visual Studio Code

佐手、 提交于 2020-01-01 02:41:11
问题 I am using Babel in my Mocha tests. To run the test in terminal I use following command: mocha --debug --compilers js:babel/register Then I can use VS Code "Attach" debugging option to attach to the test process. I can set breakpoints and it stops, but because original code is in ES6 VS Code gets confused about line numbers and such. Is there anyway to make VS Code work with this setup? My "Attach" config: { "name": "Attach", "type": "node", // TCP/IP address. Default is "localhost". "address

Mocha-web client-side tests not running with Velocity for Meteor application

旧街凉风 提交于 2019-12-30 23:25:31
问题 I have 2 samples Mocha web tests which I'm trying to run using Velocity. For some reason, client-side tests under the /tests/mocha/client folder are never executed, whereas the server side tests under the /tests/mocha/server folder run fine. Here is the structure of my project todos (meteor example project) client lib packages server tests mocha client server Thoughts ? 回答1: I ran into this problem and it was related to having the browser-policy package installed. What you need to do is look

Why should Mocha test cases be stateless?

筅森魡賤 提交于 2019-12-30 11:53:10
问题 It is a common recommendation, that Mocha test cases should not share state . In light of Mochas strongly sequential nature of execution of test cases, I really do not understand this recommentation. And more - I see it dubious. If the test cases, even asynchronic ones, are executed strictly one after another, there is no risk of time-race problems or other unpredicted execution sequence. Let's take this Mocha structure: describe describe it1 it2 // async it3 describe it4 it5 describe

Testing child_process.exec stdout

ε祈祈猫儿з 提交于 2019-12-30 08:14:18
问题 I'm trying to test the output of child process with mocha. My test looks like this: var should = require("should"), exec = require("child_process").exec; describe('users', function() { describe('andrei', function() { exec('id andrei', function(error, stdout, stderr) { it('should be part of group dev', function() { stdout.should.containEql('dev'); }) }) }) }) The problem I'm having is that the it never gets executed. I could swap the code around, to have the exec inside the it and then use

Testing child_process.exec stdout

╄→гoц情女王★ 提交于 2019-12-30 08:14:08
问题 I'm trying to test the output of child process with mocha. My test looks like this: var should = require("should"), exec = require("child_process").exec; describe('users', function() { describe('andrei', function() { exec('id andrei', function(error, stdout, stderr) { it('should be part of group dev', function() { stdout.should.containEql('dev'); }) }) }) }) The problem I'm having is that the it never gets executed. I could swap the code around, to have the exec inside the it and then use

detecting test failures from within afterEach hooks in Mocha

拟墨画扇 提交于 2019-12-30 02:36:09
问题 I'm trying to create an afterEach hook with logic that should only fire if the previous test failed. For example: it("some_test1", function(){ // something that could fail }) it("some_test2", function(){ // something that could fail }) afterEach(function(){ if (some_test_failed) { // do something to respond to the failing test } else { // do nothing and continue to next test } }) However, I have no known way of detecting if a test failed from within the afterEach hook. Is there some sort of

Mocha beforeEach vs before execution

眉间皱痕 提交于 2019-12-29 18:17:21
问题 I ran into a problem recently that I can't explain. I have alot of code in these tests so I'm going to do my best to capture the idea here I have tests that look like: describe('main page', function(){ beforeEach(function(done){ addUserToMongoDb(done); // #1 }); afterEach(function(done){ removeUserFromMongoDb(done); }); context('login', function(){ it('should log the user in, function(){ logUserIn(user_email); // #2 - This line requires the user from the beforeEach }); }); context(