chai

Angular $q promise Unit testing using Mocha, Chai, Sinon

倖福魔咒の 提交于 2019-12-12 05:38:47
问题 I'm trying to get my simple angualr $q promise unit test to work. But I've been having problems getting it to work. Here's my angular file. app.controller('theCtrl', ['$scope', '$q', function($scope, $q) { $scope.addOne = function(num) { var q = $q.defer(); if(angular.isNumber(num)) { q.resolve(num+1); } else { q.reject('NaN'); } return q.promise; } $scope.myVal = 0; $scope.promise = $scope.addOne($scope.myVal); // $scope.promise.then(function(v) {$scope.myVal = v }, function(err) {$scope

mocha chai test case for angularjs ui-route

淺唱寂寞╮ 提交于 2019-12-12 04:54:38
问题 I need to cover angularJs config file through mocha chai i tried it('should load the page.', inject(function ($location, $rootScope, $state, $httpBackend) { $httpBackend.whenGET('scripts/select-line-module/views/select-line.html').respond('<div/>'); var state = $state.get('selectLine'); $rootScope.$digest(); assert.isDefined(state.templateUrl()); expect(state.templateUrl).toBe('scripts/select-line-module/views/select-line.html'); })); I am able to cover templateUrl function but test case is

JSON report not generating for failed scenarios using protractor

我怕爱的太早我们不能终老 提交于 2019-12-12 04:12:03
问题 If my scenarios got failed the JSON report not generating. But for passes scenarios I can able to see the JSON report. Please find my config file as below. In comment prompt console I can able to see the failure message: W/launcher - Ignoring uncaught error AssertionError: expected false to equal true E/launcher - BUG: launcher exited with 1 tasks remaining 回答1: You can save the report by using a hook, so don't generate the file form the protractor.conf.js file, but use a cucumber-hook for it

Async Tests - Mocha and Chai - Ensure the done() callback is being called

与世无争的帅哥 提交于 2019-12-12 03:51:13
问题 I'm trying test my container component methods. My container had a async method that load all proposals and set in the state. Example.: loadProposal(proposalId) { return axios .get("http://localhost:9292/api/proposal_drafts/1.json") .then(response => { this.setState({ proposal: Immutable.fromJS(response.data) }) }) } So, to test this method i get the component instance and call the method (the api url is mocked). it("sets proposal in the state", (done) => { const wrapper = shallow(<Container/

angular js karma/chai - mock an authorization error

雨燕双飞 提交于 2019-12-12 03:38:46
问题 I am new to TDD and am testing an authInterceptor (I have chai/mocha/sinon available to me) in angular js, which has two functions, a request, and a responseError. I successfully tested the request function, but I don't know how (scoured the docs) to mock a 401 (unauthorized) error. Here is the interceptor: export default function AuthInterceptor($q, $injector, $log) { 'ngInject'; return { request(config) { let AuthService = $injector.get('AuthService'); if (!config.bypassAuthorizationHeader)

Using Promises to test Meteor - Mocha

╄→гoц情女王★ 提交于 2019-12-12 03:37:44
问题 I'm writing server side unit tests for a Meteor JS application. I'm using the recommended Mocha framework, with chai assertion library. I had some trouble with chaining async calls with done() callback, so I decided to use meteor/promise. I'm using and johanbrook:publication-collector to collect the published collections. When I resolve(collections) in the promise, In the subsequent then() I'm able to console.log the gathered collection, but the assert statement wouldn't work. The mocha test

How to check an element type with chai?

我们两清 提交于 2019-12-12 01:36:21
问题 I want to check whether an element is an a or a div, how do I accomplish this? this code is not working: it('has no link if required', () => { const wrapper = shallow(<AssetOverlay asset={ assetsData[0] } shouldBeLinked />); expect(wrapper.find('.overlay-asset-link')).to.be.a('a'); const wrapper1 = shallow(<AssetOverlay asset={ assetsData[0] } shouldBeLinked="false" />); //expect(wrapper1.find('.overlay-asset-link')).to.be.a('div'); }); 回答1: Well thats because chais type checking checks for

karma-sinon-chai fails after moving to Windows

那年仲夏 提交于 2019-12-11 20:36:14
问题 I have unit tests running under Karma, and am using the sinon-chai library. Everything was working fine on Mac, but now I have moved to Windows the following error is occuring: C:\Users\mchambe4\dev\simple\client>node ./node_modules/gulp/bin/gulp.js unit-tests-dev [16:29:31] Using gulpfile ~\dev\simple\client\gulpfile.js [16:29:31] Starting 'unit-tests-dev'... [16:29:31] Starting Karma server... WARN [karma]: Port 9876 in use INFO [karma]: Karma v0.12.37 server started at http://localhost

Chai fails to test async express route function

旧巷老猫 提交于 2019-12-11 18:22:39
问题 I have been trying to test my Express routes using chai and mocha. I manage to get normal tests done but it failing on async function. test case: describe('/Login wrong user', () => { it('It should attempt a login POST but with no data', (done) => { chai.request(app) .post('/login') .send({}) .then((res) => { expect(res).to.have.status(200); done(); }).catch((err) => { throw err; }); }); }); The code I want to test router.post('/', async function(req, res, next) { if (!req.body) return res

Sending Http2 Request to GRPC Server Node, Illegal Buffer

狂风中的少年 提交于 2019-12-11 16:17:09
问题 I am attempting to utilize protobuf.js and provide it a transport layer (rpcimpl) since it is transport agnostic. I can successfully convert all the proto files and to a direct grpc Client and Sever via protobuf (loadSync, lookup) to grpc's (loadObject). This allows me to get a concrete grpc implementation of server and client up with tests. The next step was to test a protobuf client (instable) to grpc server stable. This is more out of curiosity to see if we can be independent of grpc's