jasmine

How to test that an angular factory function using a promise is throwing an error in jasmine

你。 提交于 2019-12-04 17:12:31
Here's how my function looks like. var myFunc = function(){ return functionReturningaPromise() .then(function(){ //success, doesn't matter what happens here }) .catch(function(err){ //handle error here and then throw to handle higher throw new Error('Error in my function'); }) } I need the function to be this way to handle an error inside this function and then throw an error to handle on higher level. But i don't know how to test it with jasmine. I know how to control the promises for testing and my basic set up looks like this: it('Should throw an error', inject(function(alert) { var

Use Jasmine to stub JS callbacks based on argument values

拟墨画扇 提交于 2019-12-04 17:11:29
I've got a JS method in my node.js app that I want to unit test. It makes several calls to a service method, each time passing that service a callback; the callback accumulates the results. How can I use Jasmine to stub out the service method so that each time the stub is called, it calls the callback with a response determined by the arguments? This is (like) the method I'm testing: function methodUnderTest() { var result = []; var f = function(response) {result.push(response)}; service_method(arg1, arg2, f); service_method(other1, other2, f); // Do something with the results... } I want to

“ng e2e” is failling probably in reason of proxy but “ng serve” and “ng test” are working

£可爱£侵袭症+ 提交于 2019-12-04 17:07:57
I download https://github.com/blizzerand/pastebin-angular and I can successfully run "ng test" or "npm run test" (I understand both do exactly the same). C:\_pocs\ws_vsc\pastebin-angular-master>npm run test > test-angulr@0.0.0 test C:\_pocs\ws_vsc\pastebin-angular-master > ng test 10% building modules 1/1 modules 0 active29 12 2017 18:13:27.927:WARN [karma]: No captured browser, open http://localhost:9876/ 29 12 2017 18:13:27.998:INFO [karma]: Karma v1.7.0 server started at http://0.0.0.0:9876/ 29 12 2017 18:13:28.002:INFO [launcher]: Launching browsers Chrome, ChromeNoSandboxHeadless with

view doesn't load when I mock backend

匆匆过客 提交于 2019-12-04 16:57:45
I'm trying to test one particular element of user interface. To do so I need particular request to my backend to respond with predefined data, but all other requests should pass through. Here's how I do it (coffee for more readability): describe 'select2 combobox widget', ()-> httpBackendMock = () -> angular.module 'httpBackendMock', ['ngMockE2E', 'fmAppApp'] .run ($httpBackend)-> dummyCategories = [ {id: 1, name: 'foo', icon: '', user_id: 5}, {id: 2, name: 'bar', icon: '', user_id: 5}, {id: 3, name: 'baz', icon: '', user_id: 5}, {id: 4, name: 'quax', icon: '', user_id: 5} ] $httpBackend

Jasmine test to test if the controller is defined

做~自己de王妃 提交于 2019-12-04 16:47:17
New to Jasmine tests for angular. I am trying to test if the controller I defined is defined or not to begin with but I am getting error saying Expected undefined to be defined. Here is my main code: // controller logic MatchController.js (function () { 'use strict'; angular.module('app.match') .controller('MatchController', MatchController); MatchController.$inject = ['APP_CONFIG', '$authUser', '$http', '$rootScope', '$state', '$stateParams', 'SearchService', 'ConfirmMatchService', 'MusicOpsService', 'ContentOpsService', 'MatchstickService', 'MatchService', 'Restangular']; function

AngularJS Jasmine Test Fails: Failed to instantiate module

梦想的初衷 提交于 2019-12-04 16:37:55
问题 My angular app worked great and so did my tests, using karma and jasmine, until I added a dependency in ui.bootstrap . Now the app still works as expected, but I can't get my tests to run. This is what I have: app.js - added dependency in ui.bootstrap angular.module('myApp', ['ngResource', 'ngRoute', 'ui.bootstrap']).config(function(...) {...}); service.js angular.module('myApp').service('myService', function () {}) controller.js angular.module('myApp').controller('MyController', function (

How to jasmine.getenv().currentspec with jasmine 2.3

℡╲_俬逩灬. 提交于 2019-12-04 16:12:59
I want to get the passed or failed status of my test after each spec is executed: var passed = jasmine.getEnv().currentSpec.results().passed(); if (!passed) { browser.takeScreenshot().then(function(png) { writeScreenShot(png, filename, path); }; } but jasmine.getEnv().currentSpec is returning undefined , I am using Jasmine 2.3 how can I get the currentSpec with Jasmine 2.3 It's likely that you are calling this from outside of the current spec. jasmine.getEnv().currentSpec will be null if there is no current spec, for example if it is called in afterAll or beforeAll blocks. Make sure that this

Does jasmine need sinon.js?

余生颓废 提交于 2019-12-04 15:33:38
问题 I've seen examples on the web in which people use jasmine together with sinon. However, jasmine has support for spies (which as I understand is what Sinon does). So, the question is, is Sinon still useful when using Jasmine ? If Sinon is useful what exactly makes it a good addition to jasmine ? Cheers 回答1: No you dont need Sinon to work with Jasmine. But Sinon spy/mock/stubs are more convenient in some cases. There is also a minor bug in mocking setTimeout in Jasmine, which work as expected

testing Angular async services with Jasmine

随声附和 提交于 2019-12-04 15:31:50
I am trying to test a real http call with Jasmine (integration test), but when i call a method that uses $http.get, it times out and the server never gets called. I know that I am supposed to inject the implementation of $http but not sure where that should happen. searchSvc app.service('searchSvc', ['$http', '$q', searchSvc]); function searchSvc($http, $q) { return { search: function(text) { console.log('svc.search called with ', text); // this does get called return $q.when($http.get('/search/' + text)); } }; } searchSpec describe("searchTest", function() { var ctrl, svc, $http; beforeEach

Making an API call while running protractor tests

我们两清 提交于 2019-12-04 15:10:45
I have built a web application using angular2.0 and typescript . Now I am writing E2E for my site using protractor . Now, in one of my tests I need to make an API call(HTTP GET request) and use the response value as an input in my test case. So basically I want to know how to make a GET request in Protractor-Jasmine and use the result/response. Protractor runs on top of nodejs, and under the hood is calling Selenium API. You can use all of the node libraries, including request . Choose between import/require: import * as request from 'request'; var request = require('request'); And perform