karma-runner

get two divs by class name in karma test (Angular 4.0)

被刻印的时光 ゝ 提交于 2020-05-13 14:26:27
问题 I have something like this in view: <div> <div class="header-title">Example title 1</div> </div> <div> <div class="header-title">Example title 2</div> </div> In my karma test I would like to investigate all divs by class name and check if inner text is correct so I have following code in test: [...] debugTest = fixture.debugElement.query(By.css('.header-title')); elementTest = debugTest.nativeElement; [...] it('should component div has a correct value', () => { fixture.detectChanges(); const

isolateScope() returns undefined when using templateUrl

末鹿安然 提交于 2020-02-19 07:58:53
问题 I have a directive that I want to unittest, but I'm running into the issue that I can't access my isolated scope. Here's the directive: <my-directive></my-directive> And the code behind it: angular.module('demoApp.directives').directive('myDirective', function($log) { return { restrict: 'E', templateUrl: 'views/directives/my-directive.html', scope: {}, link: function($scope, iElement, iAttrs) { $scope.save = function() { $log.log('Save data'); }; } }; }); And here's my unittest: describe(

isolateScope() returns undefined when using templateUrl

谁说胖子不能爱 提交于 2020-02-19 07:58:46
问题 I have a directive that I want to unittest, but I'm running into the issue that I can't access my isolated scope. Here's the directive: <my-directive></my-directive> And the code behind it: angular.module('demoApp.directives').directive('myDirective', function($log) { return { restrict: 'E', templateUrl: 'views/directives/my-directive.html', scope: {}, link: function($scope, iElement, iAttrs) { $scope.save = function() { $log.log('Save data'); }; } }; }); And here's my unittest: describe(

Unit testing - Getting issue with Alert Controller in Ionic Framework

十年热恋 提交于 2020-02-06 20:26:52
问题 I am trying to write a testcase for a method which has been called or not. Inside that method, I am calling an alert confirmation box. I am getting an error like Failed: this.alertCtrl.create is not a function Component.ts submitTicket(comments) { if (comments.length > 0) { const prompt = this.alertCtrl.create({ title: "<span> Improve Solution </span>", message: "<span>" + 'Are you sure you want <br>' + "</span>" + "<span>" + 'to submit this improvement' + "</span>", enableBackdropDismiss:

Grunt + Karma test runner fails with “ReferenceError: module is not defined”

六月ゝ 毕业季﹏ 提交于 2020-02-04 05:11:05
问题 When running our Karma test through Grunt, the execution fails with the following error: [2013-12-30 10:14:22.690] [ERROR] config - Invalid config file! [ReferenceError: module is not defined] The Karma configuration in Gruntfile.js looks sane, I've copied it from another project, where it works just fine. Same for the karma.conf.js file, there's no difference to one of the other projects, where it works fine. I've had a look at this question, but it didn't help with fixing the issue: Testing

ChromeHeadless giving timeout when running GitLab CI pipeline with Docker Centos 7.5 image

别说谁变了你拦得住时间么 提交于 2020-02-03 23:40:33
问题 So I am trying to run Karma tests for an Angular 6 application on a docker image with Centos 7.5 using a pipeline for GitLab CI. The problem is 30 08 2018 07:09:55.222:WARN [launcher]: ChromeHeadless have not captured in 60000 ms, killing. 30 08 2018 07:09:55.244:INFO [launcher]: Trying to start ChromeHeadless again (1/2). 30 08 2018 07:10:55.264:WARN [launcher]: ChromeHeadless have not captured in 60000 ms, killing. 30 08 2018 07:10:55.277:INFO [launcher]: Trying to start ChromeHeadless

Getting “module not defined” error when using Gulp to run karma tests

纵然是瞬间 提交于 2020-02-02 04:37:11
问题 My team is working on moving from Grunt to Gulp. I have a Grunt test task that works fine, but when I try to run the tests (using gulp-karma) I get an error that says "ReferenceError: Can't find variable: module" I Googled and found a lot of posts saying to check the location of my angular-mocks.js file, and it's in the correct space (my Grunt task for the same code does work). To verify that it wasn't something weird in my code a spun up a new yo angular app and was able to replicate the

Asynchronous tasks in grunt.registerTask

房东的猫 提交于 2020-01-24 17:38:25
问题 I need to call two functions within grunt.registerTask , but the second function has to be called after the first function is done. So I was wondering if we can use callbacks or promises or other asynchronous mechanisms within grunt.registerTask . (More specifically, I need to launch karma in my first function call, and run karma in the second function call (to execute the initial unit tests). But in order to run karma, I need to launch it first. And that's what I'm missing.) 回答1: I had this:

Karma's base directory location

一个人想着一个人 提交于 2020-01-24 05:41:05
问题 Unable to load template fixtures for my tests while using karma. To simplify, Went to c:\ Created a 1.txt text file. Made a simple karma init file containing: basePath: '', Started karma using: C:\> karma start .\sample.conf.js Chrome opened up at: http://localhost:9876/?id=49209467 I then tried to navigate to: http://localhost:9876/base/1.txt but got a "NOT FOUND" error message in the browser, and a message from karma: WARN [web-server]: 404: /base/1.txt What am I missing here? 回答1: Found

accessing $scope from unit test file when using the vm “ControllerAs” syntax from AngularJS HotTowel

馋奶兔 提交于 2020-01-20 17:09:51
问题 See here for example: http://www.johnpapa.net/angularjss-controller-as-and-the-vm-variable/ As the title suggests, I'm following along on this tutorial [http://tech.pro/tutorial/1473/getting-started-with-angularjs-unit-testing] to setup unit testing and all is fine EXCEPT for the fact I can't seem to access the vm variable as my $scope . dashboard.js var controllerId = 'dashboard'; angular.module('app') .controller(controllerId, ['common', 'datacontext', dashboard]); function dashboard(common