karma-jasmine

Unit testing jQuery getJSON function errors with the fail method, using Jasmine and Karma

老子叫甜甜 提交于 2019-12-13 20:21:41
问题 I've written a unit test for a function that calls the jQuery getJSON method. The only thing that I'm testing is that it is called with the expected URL. My unit test uses a Jasmine Spy to mock the API call. However, when I run my unit tests I get this error: 1) should make a request to the expected URL when running on localhost test module getDataFromApi function TypeError: Cannot read property 'fail' of undefined In my unit test I've created a Jasmine Spy, which returns the done and fail

Mock backend server (Google Forms) in AngurJS

柔情痞子 提交于 2019-12-13 20:02:46
问题 I am using AngularJs controller to send data from form to Google Sheet. Using Jasmine I wrote unit-test, which raises the bellow issue: Error: Unsatisfied requests: POST http://localhost:5000/google-form at Function.$httpBackend.verifyNoOutstandingExpectation (.../angular-mocks/angular-mocks.js:1474:13) After googling and going through some questions in stackowerflow, I decided to post the question as I didn't find a solution for it. Here is the code for your references: Angular Controller /*

How to remove module not found error in angular?

£可爱£侵袭症+ 提交于 2019-12-13 12:42:32
问题 I make a simple example of controller here . http://plnkr.co/edit/dplJ6sf4kgiwJ5pXu4GE?p=preview and I want to test the controller .I am able to test my controller online Here is my code to test my controller online http://plnkr.co/edit/xzvhXHPoUdulOM9clOkQ?p=preview But when I try to run that same work on my computer my test case are fail I am getting error this Module 'app.home' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that

Imports in vanilla/pure JS testing with protractor and relative paths

不问归期 提交于 2019-12-13 05:36:45
问题 Until now, I was testing my non-Angular website (I only have JS, no node, not even ES6) using Jasmine, Karma and Travis CI. I am now trying to write functional tests (in case my vocabulary is off, I mean scenario tests for which I want to test "visual/UI" tests) and google directed me to Protractor. Importing For now, I will completely disregard Travis CI . The only way I have found to "reach" my page was with a local path browser.get('file:///C:/local/path/to/project/index.html'); For now, I

test broke when changed model with interfaces to classes

十年热恋 提交于 2019-12-13 05:31:09
问题 Sorry if its a bit long but I wanted to explain myself well. I have a test for an api call im performing from my service to receive a simple json. (Karma-jasmin/angular2) this is the call from my service: @Injectable() export class MyService { constructor(private _myApiService:MyAPIService) { } public getCarsData():Observable<Car[]> { return this._myApiService.getCurrentCarData().map(res => res.carList); } } this is getCurrentCarData() : export interface CarsListResponse extends

Karma reporter with Grunt prints [object Object] instead of describe strings

我是研究僧i 提交于 2019-12-13 05:14:27
问题 With grunt, my failing tests output like so: Chrome 37.0.2062 (Mac OS X 10.9.5) [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] should return full list if no filter options are set FAILED When I run the tests without grunt,

Howto mock a service used in a directive

只愿长相守 提交于 2019-12-13 04:53:32
问题 We have the following directive : (function() { 'use strict'; ff.directive('mySwitchUserDirective', mySwitchUserDirective); mySwitchUserDirective.$inject = ['SessionService']; function mySwitchUserDirective(SessionService) { var directive = { restrict: 'E', template: '<img ng-src="{{userImage}}" width="35px" style="border-radius: 50%; max-height: 35px;" />', link: linkFunc }; return directive; function linkFunc(scope, element, attrs, ctrl) { scope.userImage = SessionService.get().authUser

AngularJS - Unit test for http get to JSON file

纵饮孤独 提交于 2019-12-13 04:13:07
问题 I am trying to write a unit test to test a simple factory that performs a http.get to retrieve a JSON file. The factory is called within my controller. Here's a plunker showing my http.get: http://plnkr.co/edit/xg9T5H1Kreo4lwxzRQem?p=preview Ctrl: app.controller('MainCtrl', function($scope, $http, factoryGetJSONFile) { factoryGetJSONFile.getMyData(function(data) { $scope.Addresses = data.Addresses.AddressList; $scope.People = data.Names.People; }); }); Factory: app.factory('factoryGetJSONFile

Testing branches jasmine angular

Deadly 提交于 2019-12-13 03:28:54
问题 I want to test following function: ngOnInit() { this.hmDataService.loadData().subscribe((data) => { this.description= data.description; this.date= data.date; const restoredID= this.localStorage.getItem('key'); if (restoredID) { this.type = restoredID.toString(); this.selectedMenu= this.option.filter((rf: any) => { return rf.value === restoredID; })[0]; } this.createTable(this.id, this.data, this.type); }); } I need it for the test coverage which expect from me to test the branches. import {

Uncaught Error: Module name “lib/chai” has not been loaded yet for context: use require([])

倾然丶 夕夏残阳落幕 提交于 2019-12-13 02:46:58
问题 i m using karma-mocha ..my karma.conf file is working with karma-jasmine...but not working with karma-mocha....my karma.conf file:-- module.exports = function(config){ config.set({ basePath : '../app', preprocessors: { '**/*.html':'ng-html2js' }, ngHtml2JsPreprocessor: { prependPrefix: '/' }, files : [ 'node_modules/jquery/**/*.js', 'lib/angular/angular.js', 'lib/angular/angular-*.js', '../test/lib/angular-mocks.js', '../test/lib/sinon-1.15.0.js', '../test/chai/chai.js', 'js/**/*.js', '..