mocha

Mocha beforeEach vs before execution

旧时模样 提交于 2019-12-29 18:16:46
问题 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(

在vscode里配置mocha进行node代码测试

我的未来我决定 提交于 2019-12-29 13:01:37
关于mocha Mocha是一个能够运行在Node和浏览器中的多功能的JavaScript测试框架,它让异步测试简单且有趣。Mocha连续地运行测试,并给出灵活而精确的报告,同时能够将错误精确地映射到测试用例上。它托管在 GitHub 上。 开始配置 项目中需要进行单元测试,而我常用的开发工具是vscode,于是想在vscode里实现调试时就可以进行测试。 第一步: 安装mocha,这里我使用的是作为开发依赖安装在项目中(全局安装mocha没学会怎么在vscode里配置) $ npm install --save-dev mocha 第二步:点击vscode调试菜单-->打开配置 第三步:点击右下角的“添加配置”按钮,并选择“Mocha测试” 默认的配置是这样的: { "type": "node", "request": "launch", "name": "Mocha Tests", "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", "args": [ "-u", "tdd", "--timeout", "999999", "--colors", "${workspaceFolder}/test" ], "internalConsoleOptions": "openOnSessionStart",

How can I check that two objects have the same set of property names?

流过昼夜 提交于 2019-12-28 01:49:20
问题 I am using node, mocha, and chai for my application. I want to test that my returned results data property is the same "type of object" as one of my model objects (Very similar to chai's instance). I just want to confirm that the two objects have the same sets of property names. I am specifically not interested in the actual values of the properties. Let's say I have the model Person like below. I want to check that my results.data has all the same properties as the expected model does. So in

Spectron using mocha is not working as expected

匆匆过客 提交于 2019-12-25 17:59:22
问题 I have written one login test case for my electron app using mocha via spectron tool. I am facing following issues. Sometimes my script works completely fine, and I am able to pass username and password value to web elements and login is executed. Sometimes I am able to see testcases as passed, but values are not passed to username and password web elements. One day I tried to clear my system temp files and executed "npm test" command and script executed properly, but again next day facing

Mocha + Cucumber to mock the Net response

瘦欲@ 提交于 2019-12-25 12:42:12
问题 The following is the app/models/websites.rb class Masterpiece < ActiveRecord::Base validates_presence_of :title, :link validates_uri_existence_of :link, :allow_redirect => false end The second validation is from the plugin Validates Existence of URI plugin The following is the features/support/mocha.rb file require 'mocha' World(Mocha::API) Before do mocha_setup @http_mock = mock('Net::HTTPResponse') @http_mock.stubs(:code => '200', :message => "OK", :content_type => "text/html", :body => '

How to make `it.only` environment-aware using mocha?

北城余情 提交于 2019-12-25 12:34:37
问题 Mocha supports it.only syntax to reduce the amount of tests to run. In our team, a developer might use it.only temporally within a code base. Now it happened that such an only test was approved and deployed by accident. This led the build server to happily run only one test and to declare that build a success. My question now becomes: Is there a way to tell mocha: It should only allow only on a developer's machine? Can it be make environment aware so that either all tests always run on a

Error: Timeout of 2000ms exceeded. For async tests and hooks. Unit test with mocha and chai

人盡茶涼 提交于 2019-12-25 09:40:48
问题 While establishing the connection using socket Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done( )" is called; if returning a Promise, ensure it resolves. Given below is the code reference of the same beforeEach(function(done) { var socketOptions = {}; var socket = io.connect("http://localhost:5000", socketOptions); socket.on('connect', function () { console.log('Connection Established'); setTimeout(done, 500); }); socket.on('error', function (err) { console.log(

Testing Typescript Generated Classes with node.js, Mocha and mocha-jsdom?

十年热恋 提交于 2019-12-25 08:36:40
问题 I would like to run unit tests from bash to test my Typescript generated Javascript classes using mocha and mocha-jsdom. I'm using mocha-jsdom because I want to emulate the dom in my tests but run unit tests from bash. I've seen a few examples where they use the frontend testing framework for mocha in a browser, but I haven't seen any where they are run from bash. It appears that I am unable to include the Javascript classes generated from Typescript in my mocha unit tests. var jsdom =

NodeJS/Passport - Testing user login with mocha and superagent

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 07:33:07
问题 I have built a login process with a basic MEAN stack and using passport for the authentication process. I am trying to set up a test to make sure the login process is working. To do the login part here is the code I used: it ('login', function(done) { agent.post(config.web.vhost + '/login') .send({ email: 'bruce@wayne.inc', password: 'batman' }) .end(function(err, res) { if (err) console.log('error' + err.message); res.should.have.status(200); done(); }); }); I get the following error: no

DynamoDB javascript SDK batchWriteItem doesn't complete unless I increase write capacity

六月ゝ 毕业季﹏ 提交于 2019-12-25 06:28:06
问题 I'm running a series of unit tests (node.js 4.x, aws-sdk, mocha) which load data into a table before each test then clears the table after the test. I have two tests that are failing because of a ConditionExpression which triggers a ConditionCheckFailedException . But if I increase the read/write capacity they tests pass. It's my understanding that the SDK handles throttling exceptions and retries them for you so why wouldn't my tests just run slower and pass? Instead it seems as though the