mocha

createAttachment using mocha-allure-reporter

∥☆過路亽.° 提交于 2019-12-24 20:14:54
问题 Im trying to add a screenshot as an attachment in allure reports using mocha-allure-reporter. I dont get any errors, but the screenshot does not have save in ./reports/allure-results, and no console log either. Is this the correct way to use allure.createAttachment? declare const allure: any; afterEach('first step', function () { allure.createStep('initial', () => { browser.takeScreenshot().then(function (png) { allure.createAttachment('Screenshot', function () { return new Buffer(png,

How to test a Webpack bundle that has external dependencies?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 20:12:07
问题 I'm new to Webpacker and Rails in general. I recently moved to using Webpacker to bundle React components. Since part of the application still uses the asset pipeline, some dependencies are still stored in vendor/assets/javascript , and accessible as globals. The Webpack bundle declares those dependencies as external, and when serving the app, everything works great, as Rails serves the dependencies, which are then picked up by the bundle. Now I want to start testing the bundle using

How do I get mocha to execute tests in all subfolders recursively?

≡放荡痞女 提交于 2019-12-24 19:31:54
问题 I have my tests grouped in folders, like this: test/ ├── unit/ ├── integration/ └── acceptance/ In each of the above folders, there are a number of test files (e.g. test.js ) I execute my different test suites with the following commands: mocha test/unit/**/*.js mocha test/integration/**/*.js mocha test/acceptance/**/*.js I recently decided to add a subfolder to test/unit , to organise things a bit: test/ └── unit/ ├── subfolder/ │ └── new.test.js ├── foo.test.js └── bar.test.js But now mocha

What is the proper way of mocking my controller 'create' action that includes an external API call with mocha

折月煮酒 提交于 2019-12-24 18:33:47
问题 I am having a little bit of a difficult learning curve to test a create controller action that calls an external api call with Rails, mocha, and webmock. Below is the following controller code that I want to test. def create @response = Cdnify.create_cdn_resource(cdn_params) if @response.parsed_response['resources'] flash[:notice] = 'Successfully Created Resource.' else @response.parsed_response['errors'].each do |error| flash[:error] = "#{error['code']}" + ': ' + "#{error['message']}" end

angular-mock testing in Karma+Mocha can't find module

泪湿孤枕 提交于 2019-12-24 16:07:48
问题 I'm learning AJS unit testing, with RequireJS, Karma, Mocha, Chai and angular-mocks. I've had some luck with the first four, but need to get into "real" testing and can't get angular-mocks to work. There's a lot going on, so I'll be as succinct as possible. test/karma.conf.js module.exports = function (config) { config.set({ // requirejs may need to be listed before other modules (see https://github.com/princed/karma-chai-plugins#limited-requirejs-support) frameworks: ["requirejs", "mocha",

Including libraries fails - what is document root?

只愿长相守 提交于 2019-12-24 16:00:23
问题 I have a file ( src/inc.js ) that loads certain files into my browser using jquery's ajax: $.ajax({url: 'somefile.js', async: false, dataType: 'script', error: function(qXHR, textStatus, errorThrown) { console.log( '[' + textStatus + '] ' + errorThrown + ' with: ' + this.url ); } }); and this file gets included via browserification into my browser (phantomjs). Gruntfile.js : browserify: { libs: { src: ['src/*.js'], dest: 'test/libs.js' } } and handed to karma (in Gruntfile.js ): karma: {

How to test factory pattern using Mocha in Ruby?

為{幸葍}努か 提交于 2019-12-24 13:16:15
问题 I'm having trouble getting this simple mocha test to work Diclaimer I'm new to mocha! My Factory class # lib/fabtory.rb class Factory def self.build klass, *args klass.new *args end end My test code # test/test_factory.rb class FactoryTest < MiniTest::Unit::TestCase # my fake class class Fake def initialize *args end end def test_build_passes_arguments_to_constructor obj = Factory.build Fake, 1, 2, 3 obj.expects(:initialize).with(1, 2, 3).once end end Output unsatisfied expectations: -

mocha and nested objects

谁说胖子不能爱 提交于 2019-12-24 12:50:39
问题 Excuse if this is a silly question, I am new to mocking. I am able to use mocha to do things like: person.expects(:first_name).returns('David') How can I mock a nested object? Say I have a Product that belongs to a Person and I want to get the first name of that person. In my app I might do it like this: product.person.first_name How would I get the same result using a mock? 回答1: as an alternative to shingara's answer, you could use mocha's any_instance method "which will detect calls to any

Supertest fails to test repeated post request

╄→尐↘猪︶ㄣ 提交于 2019-12-24 10:14:19
问题 I'm testing an api that creates users. The api does not allow the creation of users with the same login value. So I wrote the tests below: const app = require('../config/express'); //exports a configured express app const request = require('supertest'); const {populateUsers} = require('../seeders/users.seed'); beforeEach(populateUsers);//drop and populate database with some seeders describe('POST /v1/users', () => { it('#Post a new user - 201 status code', (done) => { request(app) .post('/v1

How/What is the best way to auto create/save text file version of automated test reporter logs

隐身守侯 提交于 2019-12-24 08:31:06
问题 It's my first time building proper selenium tests (I've touched on IDE before). I'm using Selenium with NodeJS, WebdriverIO, Mocha framework, wdio-spec-reporter and wdio-browserstack-service. I have managed to create my tests, suites specified in conf.js , hooked into browserstack (so when i run in command line, it creates a text log and video in browserstack). Now I've been asked to do something so that when a test/suite is run it will automatically save the text logs as a text file. My