karma-jasmine

Angular tests failing with Failed to execute 'send' on 'XMLHttpRequest'

本秂侑毒 提交于 2019-11-28 15:29:30
I am trying to test my angular 4.1.0 component - export class CellComponent implements OnInit { lines: Observable<Array<ILine>>; @Input() dep: string; @Input() embedded: boolean; @Input() dashboard: boolean; constructor( public dataService: CellService, private route: ActivatedRoute, private router: Router, private store: Store<AppStore>) { } } However, a simple "should create" test throws this cryptic error... NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'ng:///DynamicTestModule/module.ngfactory.js'. so I found this question, which suggests that the issue is the

Karma unit testing: Module name “react” has not been loaded yet for context: _. Use require([])

自古美人都是妖i 提交于 2019-11-28 13:58:45
I am trying to set up the unit testing framework for react. While doing so, the following error has occurred. I have searched all over the internet with no solution that is working. below are the errors shown and code/packages that I am using. debug error 04 03 2016 04:48:46.340:DEBUG [phantomjs.launcher]: Error: Module name "react" has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded 04 03 2016 04:48:46.341:DEBUG [phantomjs.launcher]: http://localhost:9876/base/node_modules/requirejs/require.js?6f53c895855c3743ac6fb7f99afc63ca5cdfd300:140 in

Angular 4 unit test for KeyboardEvent

馋奶兔 提交于 2019-11-28 11:37:00
问题 I'm trying to write a unit test for a utility I've written to limit the characters available to an input field. The method takes the keyboard event and determines which event.code has been fired and either returns true or event.preventDefault(). This works great but I cannot test it in jasmine / karma. Current input from template <input [(ngModel)]="donationValue" formControlName="donationAmount" type="tel" class="donation-amount" (keydown)="checkCharacter($event)" placeholder="Enter Amount..

How to resolve promises in AngularJS, Jasmine 2.0 when there is no $scope to force a digest?

£可爱£侵袭症+ 提交于 2019-11-28 06:42:56
It seems that promises do not resolve in Angular/Jasmine tests unless you force a $scope.$digest() . This is silly IMO but fine, I have that working where applicable (controllers). The situation I'm in now is I have a service which could care less about any scopes in the application, all it does it return some data from the server but the promise doesn't seem to be resolving. app.service('myService', function($q) { return { getSomething: function() { var deferred = $q.defer(); deferred.resolve('test'); return deferred.promise; } } }); describe('Method: getSomething', function() { // In this

Karma/Jasmine times out without running tests

烈酒焚心 提交于 2019-11-28 05:14:31
I'm trying to run Karma/Jasmine from Grunt on a project generated with http://newtriks.com/2013/12/31/automating-react-with-yeoman-and-grunt/ Karma launches PhantomJS (or Chrome) and, depending on singleRun, it either times out or just sits there and does nothing. I've tried changing captureTimeout and browserNoActivityTimeout based on reading solutions from people with similar problems, but it doesn't seem to work. My relevant pacakge versions etc.: NodeJS: 0.10.25 Karma: 0.12.16 Webpack: 1.1.11 webpack-dev-server: 1.4.1 karma-jasmine: 0.1.5 Linux: Ubuntu 14.04 I've found someone with the

Angular unit-test controllers - mocking service inside controller

这一生的挚爱 提交于 2019-11-28 04:33:59
I have the following situation: controller.js controller('PublishersCtrl',['$scope','APIService','$timeout', function($scope,APIService,$timeout) { APIService.get_publisher_list().then(function(data){ }); })); controllerSpec.js 'use strict'; describe('controllers', function(){ var scope, ctrl, timeout; beforeEach(module('controllers')); beforeEach(inject(function($rootScope, $controller) { scope = $rootScope.$new(); // this is what you missed out timeout = {}; controller = $controller('PublishersCtrl', { $scope: scope, APIService: APIService, $timeout: timeout }); })); it('should have scope

Karma: Running a single test file from command line

£可爱£侵袭症+ 提交于 2019-11-28 04:02:19
So, I've been looking all over for this, found "similar" answers here, but not exactly what I want. Right now if I want to test a single file with karma, I need to do fit() , fdescribe() on the file in question... However, what I do want is to be able to just call karma, with the config file, and direct it to a specific file, so I don't need to modify the file at all, ie: karma run --conf karma.conf.js --file /path/to/specific/test_file.js is it possible to do this? Or with any helper? (using grunt or gulp?) bvaughn First you need to start karma server with karma start Then, you can use grep

Firebase App named '[DEFAULT]' already exists (app/duplicate-app)

a 夏天 提交于 2019-11-28 02:39:53
问题 Hi I am trying to unit test while developing a simple web with AngularJS + Firebase, but I have a problem defining the spec and trying the test runner myProject/test/spec/main.js : describe('Controller: MainCtrl', function() { var MainCtrl, scope beforeEach(module('MainApp')); beforeEach(inject(function ($controller, $rootScope) { scope = $rootScope.$new(); MainCtrl = $controller('MainCtrl', { $scope: scope }) })); it('should....',function(){ expect(true).toBe(true) }) it('should2....'

how to test and resolve Controller data (.then function()) promise and get orginal Data in Jasmine2

泪湿孤枕 提交于 2019-11-28 02:25:23
I am testing a controller that uses a service that returns a promise. I need to resolve promise. I am using Jasmine 2. Here is Spec code beforeEach(inject(function ($controller, $rootScope, _myService_, _$q_, _$rootScope_, _$httpBackend_, $http) { scope = $rootScope.$new(); $q = _$q_; $httpBackend = _$httpBackend_; $rootScope = _$rootScope_; myService = _myService_; $http = $http; ctrl = $controller('Ctrl', { '$scope': scope, 'myService': myService }); spyOn(myService, "getDateRangeData").and.callThrough(); })); it('getDateRangeData return Data obj', function() { myService.getDateRangeData()

Karma - Chrome failed 2 times (cannot start). Giving up

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 00:41:16
I've been trying to run my tests using karma-chrome-launcher, but everytime I run my tests it throws this error: INFO [launcher]: Starting browser Chrome ERROR [launcher]: Cannot start Chrome INFO [launcher]: Trying to start Chrome again (1/2). ERROR [launcher]: Cannot start Chrome INFO [launcher]: Trying to start Chrome again (2/2). ERROR [launcher]: Cannot start Chrome ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up. Here's my karma.conf.js code: // Karma configuration // Generated on Mon Mar 23 2015 14:04:19 GMT-0300 (BRT) module.exports = function(config) { config.set({ /