karma-jasmine

How to load mock data from JSON file in Angular 2 karma jasmine test?

喜欢而已 提交于 2019-12-04 02:58:23
I writing karma jasmine test case for angular 2 , And we came across requirement to mock data in separate JSON file as data is huge (want to make sure code cleanness). For this I searched a lot but didn't find proper solution. We already mocking HTTP service using MockBackend , So we can't use HTTP service of angular to load JSON as it eventually request will go to MockBackend. So is there any another way without using any third party lib like jasmine-jquery or Karma-jasmine-preprocessor ? More kind of Angular JS 2 way . I had the same issue! Finally, I realized that just using the require()

Angular 2 and jQuery - how to test?

故事扮演 提交于 2019-12-04 01:38:08
I am using Angular-CLI (webpack version) for my Angular 2 project and I also need to use jQuery (sadly. In my case, it's a dependency of Semantic-UI and I am using it for handling menu dropdowns). The way I am using it: npm install jquery --save Then listing in it angular-cli.json file in the scripts array: scripts": [ "../node_modules/jquery/dist/jquery.min.js" ] So it gets included into bundle file and this file is automatically used to root html file: <script type="text/javascript" src="scripts.bundle.js"> Then declare var $: any; in files where I need it and it works well. However there is

Angular 4 unit testing with jasmine /karma with http post mocking - how to fix

最后都变了- 提交于 2019-12-04 00:55:47
问题 I have a service I want to unit test in angular 4 typescript jasmine. Now, the http is doing a post , and it returns an identity, however.. it is not sending anything. I want to just have good code coverage but i don't understand how to quite complete this mocking statement. here is the method for http post in my service file addSession() { let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); return this.http.post(this.url,

Ionic Jasmine : env.stopOnSpecFailure is not a function after compiled successfully

喜夏-厌秋 提交于 2019-12-04 00:18:47
Using Ionic with jasmine-karma, while run test, getting success compile but in jasmine dashboard getting empty screen with error in console. Following tutorial : https://leifwells.github.io/2017/08/27/testing-in-ionic-configure-existing-projects-for-testing/ "ts-loader": "^4.1.0", "jasmine-core": "^2.99.1" Error Messages : TypeError: env.stopOnSpecFailure is not a function at adapter.js:26 Error: Module build failed: TypeError: Cannot read property 'afterCompile' of undefined The failure occurs in your version of karma-jasmine which tries to use the stopOnSpecFailure function. That function is

Issue with angular.mock.inject method

若如初见. 提交于 2019-12-03 22:34:47
问题 I am using folloing jasmine test case 'use strict'; describe('companyService', function() { var $httpBackend, companyService; beforeEach(angular.mock.module('myApp')); beforeEach(angular.mock.inject(function(_$httpBackend_ , _companyService_) { $httpBackend = _$httpBackend_; companyService = _companyService_; })); it('should return a promise for getCompany function', function() { // expect(typeof companyService.getCompany('foobar').then).toBe('function'); }); }); i am getting the following

testing ui-router stateprovider 'resolve:' values

不羁岁月 提交于 2019-12-03 22:22:56
I'm using jasmine+karma to run the following code... and get the following error: Expected { then : Function, catch : Function, finally : Function } to equal 123. Can someone help me understand why I don't get a resolved value for my promise. thanks 'use strict'; angular .module('example', ['ui.router']) .config(function($stateProvider) { $stateProvider .state('stateOne', { url: '/stateOne', resolve: {cb: function($q) { var deferred = $q.defer(); deferred.resolve(123); return deferred.promise; }}, controller: function($scope, cb) {console.log(' * in controller', cb);}, templateUrl: 'stateOne

How to test a directive's controller using angularJS-karma-jasmine?

百般思念 提交于 2019-12-03 16:00:40
Goal: Write a passing test for the waCarousel directive scope variable: self.awesomeThings . Expect this test pass when self.awsomeThings.length.toBe(3) to is true? Question: How can I properly write this test? rather how do I inject a directives controller? Directive: angular.module('carouselApp') .directive('waCarousel', function() { return { templateUrl: '../../../views/carousel/wa.carousel.html', controller: function($scope) { var self = this; self.awesomeThings = [1, 2, 3]; return $scope.carousel = self; } } }); Unit Test: describe('waCarousel Unit', function() { // am I missing a

karma.conf.js automatic file ordering?

旧巷老猫 提交于 2019-12-03 13:33:30
I have a large angularjs project ordered by features. I'd like to setup unit testing but I'm having trouble getting the karma.conf.js file ordering setup. I tried specifying a simple glob pattern like **/*.js but many of my modules failed to load due to the ordering that they're included in Karma when ran. As I understand, it's alphabetical, first match. I was able to resolve this by manually figuring out the ordering by doing something like this: // list of files / patterns to load in the browser files: [ // External scripts 'bower_components/angular/angular.js', 'bower_components/angular

Error: Cannot find module 'jasmine-core'

对着背影说爱祢 提交于 2019-12-03 13:15:23
问题 I installed the following for testing: "devDependencies": { "jasmine-core": "^2.4.1", "karma": "^0.13.22", "karma-jasmine": "^0.3.7", "karma-phantomjs-launcher": "^1.0.0" } After running karma start I get the following error: Doing a search this is the first question with the same problem: karma start Cannot find module 'jasmine-core' However I've tried both answers, installed jasmine-core globally and I already did npm install jasmine-core --save-dev :( My test/index.html <!DOCTYPE html>

console.log not working on any karma project

末鹿安然 提交于 2019-12-03 12:48:51
UPDATE: tl;dr; I updated my npm packages and couldn't see any console.log output anymore in karma. Looks like it's b/c of a behavior change that only shows console.log output at the LOG_DEBUG level and hides it at LOG_INFO . When was that change made and is there a way to revert it? ORIGINAL: When I run karma from a windows command prompt I cannot see the output of console.log . I used to see it fine in many projects, but now it's suddenly not working in any of my projects. This seems to have changed after I ran npm update in one project. I did not npm update any other project, but they all