chai

Trouble displaying test results in browser with Mocha, Chai, and webdriver.io

二次信任 提交于 2020-02-06 08:04:07
问题 I am using Webdriver.io with Mocha and Chai. I've written several tests that work great from the command line. It opens the Chrome browser, runs the tests, and displays the resultsin the command line. However I am having issues getting the results of the tests to display in the browser view (have a presentation that I would like to show the tests in the browser view). I'm using the mocha html template for viewing tests in the browser, but it only displays "passes: 0failures: 0duration: 0s" in

chai-http/superagent : set Content-Type of mulipart form field

大憨熊 提交于 2020-02-04 03:50:54
问题 Uploading a file in an integration test as follows: chai.request(server.instance) .post('/profile/photo/0') .set('Access-Token', accessToken) .set('API-Key', testConfig.apiKey) .set('Content-Type', 'image/png') .field({contentId: 'foobar'}) .attach('file', fs.readFileSync(__dirname + '/file.png'), 'file') .end((err, res) => { console.log(JSON.stringify(res.body)) res.should.have.status(200) done() }) The content type of the multipart file is: application/octet-stream and I need it to be image

sinon calledWith(new Error()) and with exact message

纵饮孤独 提交于 2020-01-24 04:28:13
问题 i need to test this function : //user.js function getUser(req,res,next){ helper.get_user(param1, param2, (err,file)=>{ if (err) return next(err);} my test function : it ("failed - helper.get_user throws error",sinon.test(function () { var req,res; var get_user = this.stub(helper,"get_user") get_user.yields(new Error("message")); var next = sinon.spy(next); user.get_user(req,res,next); expect(next).to.have.been.calledWith(new Error("other message")); })) for my assertion I'm using sinon-chai

Cannot able to access dynamic test values inside “it” function of mocha, though it is accessible inside “describe” function

99封情书 提交于 2020-01-17 04:50:06
问题 I was able to access dynamic values inside describe exactly but not inside it block. (mostly I am getting last value of the array) for( var i =0 ;i< dynamicValues.length; i++){ (function wrap(dynamicValue){ describe("condition", function(){ // It is logging correct value. console.log(dynamicValue) it("should be accessible", function(){ // It is not logging correct value, but logging last value of array. console.log(dynamicValue); } }) }(dynamicValues[i])); } How to get same "environment" of

Compare arrays of objects independent of the order

為{幸葍}努か 提交于 2020-01-14 10:23:17
问题 I have 2 arrays of objects and I have to compare them, but the order of the objects DOES NOT matter. I can't sort them because I won't have their keys' names because the functions must be generic. The only information that I'll have about the array is that both array's objects have the same amount of keys and those keys have the same name. So the array1 must contain the same objects as the array2. var array1 = [{"key1":"Banana", "key2":"Yammy"}, {"key1":"Broccoli", "key2":"Ew"}]; var array2 =

NightmareJS multiple reports from same test

三世轮回 提交于 2020-01-14 06:37:10
问题 Thanks to @pipo_dev I was able to solve an issue I was having with multiple evaluations in NightmareJS, one thing that I would like to know is if I can provide multiple reports for the same test, take the following as an example: describe('test google search results', function() { this.timeout(15000); it('should find the nightmare github link first', function(done) { var nightmare = Nightmare({show: true}) nightmare .goto('http://google.com') .wait(1000) .type('form[action*="/search"] [name=q

How to test John papa vm.model controllers and factories unit testing with jasmine?

梦想与她 提交于 2020-01-14 02:08:32
问题 Ive been using John Papa's style guide for my angular apps and Im just starting to get into the testing. However I can't seem to find any good documentation regarding testing the style with mocha, chai, and jasmine. Here is an example of one of my controllers (function () { 'use strict'; angular.module('app').controller('appController', appControllerFunction); function appControllerFunction($scope, $rootScope, $location, dataService, dataFactory) { var vm = this; function getData() { vm.data

How to test functions within Javascriptcore?

余生长醉 提交于 2020-01-13 16:23:00
问题 I have seen many examples where someone takes a JavaScript function and evaluates it by doing something like: JSContext *context = [[JSContext alloc] initWithVirtualMachine:[[JSVirtualMachine alloc] init]]; [context evaluateScript:@"var add = function(a, b) {return a + b;}"]; NSLog(@"%@", [context[@"add"] callWithArguments:@[@20, @30]]); //Output is 50 But how can we run test cases on the function? By calling arguments we can see the result (assuming it doesn't throw an exception). In the

How to test functions within Javascriptcore?

大憨熊 提交于 2020-01-13 16:20:17
问题 I have seen many examples where someone takes a JavaScript function and evaluates it by doing something like: JSContext *context = [[JSContext alloc] initWithVirtualMachine:[[JSVirtualMachine alloc] init]]; [context evaluateScript:@"var add = function(a, b) {return a + b;}"]; NSLog(@"%@", [context[@"add"] callWithArguments:@[@20, @30]]); //Output is 50 But how can we run test cases on the function? By calling arguments we can see the result (assuming it doesn't throw an exception). In the

Mocha API Testing: getting 'TypeError: app.address is not a function'

僤鯓⒐⒋嵵緔 提交于 2020-01-11 15:47:33
问题 My Issue I've coded a very simple CRUD API and I've started recently coding also some tests using chai and chai-http but I'm having an issue when running my tests with $ mocha . When I run the tests I get the following error on the shell: TypeError: app.address is not a function My Code Here is a sample of one of my tests ( /tests/server-test.js ): var chai = require('chai'); var mongoose = require('mongoose'); var chaiHttp = require('chai-http'); var server = require('../server/app'); // my