Error: No provider for “framework:jasmine”! (Resolving: framework:jasmine)

Grunt –force works because you tell it to bypass the karma tests. Notice if you run grunt –force, it’ll still say “Done, but with warnings”. To fix: add “karma-jasmine” and “karma-chrome-launcher” (or whatever launcher you use) to the devDependencies in packages.json and run npm install again. npm install karma-jasmine –save-dev npm install karma-chrome-launcher –save-dev This … Read more

Issue running karma task from gulp

How are you running your tests with Gulp? I came up against this issue recently on OSX, running node v0.11.14 and gulp 3.8.10, whenever there were failing tests. Changing from the recommended: gulp.task(‘test’, function(done) { karma.start({ configFile: __dirname + ‘/karma.conf.js’, singleRun: true }, done); }); To: gulp.task(‘test’, function(done) { karma.start({ configFile: __dirname + ‘/karma.conf.js’, singleRun: … Read more

Angular 2 unit testing – getting error Failed to load ‘ng:///DynamicTestModule/module.ngfactory.js’

I ran into this issue myself yesterday. The problem was that I had an Input() property on my component class that I wasn’t setting in the test. So for example, in my-component.ts: @Component({ selector: ‘my-component’ }) export class MyComponent { @Input() title: string; } and my-component.spec.ts: beforeEach(() => { fixture = TestBed.createComponent(MyComponent); component = fixture.componentInstance; … Read more

Testing Angular component with unsubscribe Error during cleanup of component

The “Error during component cleanup” error message happens because when ngOnDestroy() is called, this.routeSubscription is undefined. This happens because ngOnInit() was never invoked, meaning that you never subscribed to the route. As described in the Angular testing tutorial, the component isn’t initialized fully until you call fixture.detectChanges() the first time. Therefore, the correct solution is … Read more

Unit-testing directive controllers in Angular without making controller global

I prefer at times to include my controller along with the directive so I need a way to test that. First the directive angular.module(‘myApp’, []) .directive(‘myDirective’, function() { return { restrict: ‘EA’, scope: {}, controller: function ($scope) { $scope.isInitialized = true }, template: ‘<div>{{isInitialized}}</div>’ } }) Then the tests: describe(“myDirective”, function() { var el, scope, … Read more

How to debug Karma tests in Visual Studio Code?

You can debug Karma by attaching the debugger to a Chrome instance. You’d want to set your launch.json config to something like this: { “version”: “0.2.0”, “configurations”: [ { “type”: “chrome”, “request”: “attach”, “name”: “Attach Karma Chrome”, “address”: “localhost”, “port”: 9333, “pathMapping”: { “https://stackoverflow.com/”: “${workspaceRoot}/”, “/base/”: “${workspaceRoot}/” } } ] } But you also need … Read more

Mocking AngularJS module dependencies in Jasmine unit tests

If you want to mock a module that declare one or more services I have used this code: beforeEach(function(){ module(‘moduleToMock’); module(function ($provide) { $provide.value(‘yourService’, serviceMock); }); }); This is useful if the service you want to mock is also a service that you want to unit test (in another jasmine describe). The solution proposed by … Read more

View Karma Test Output in a Browser?

AFAIK, the previous two answers are correct in that you’ll want to run the tests in a browser; click DEBUG and view the output in the console. Politely contradicting the previous answer, I regularly do this and step-through debug with full variable interaction using Karma. The proper answer to your question, because what you want … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)