How do I fix my generator-angular project so that grunt test works?

I seem to have fixed my problem, for anyone with a similar problem: Within my karma.conf.js I added the following: plugins: [ ‘karma-chrome-launcher’, ‘karma-jasmine’ ], At first I added ‘karma-jasmine’ but was then met with “Can not load “Chrome”, it is not registered!” This was solved by adding ‘karma-chrome-launcher’ as a plug-in Not sure if … Read more

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

Ah, obvious now…I can access the vm variable through making a reference to the controller that’s created in the test: it(“should assign Dashboard as title”, function () { var vm = controller(“dashboard”, { $scope: scope }); expect(vm.title).toBe(“Dashboard”); });

How to pass a custom error message to a jasmine matcher?

Update 2022; Use .withContext(…) method instead of below (as optional parameter is deprecated). Jasmine already supports optional parameter in all matchers (toBe, toContain, and others), so you can use: expect(true).toBe(false, ‘True should be false’). Then in output it will look like this: Message: Expected true to be false, ‘True should be false’. Link to commit … Read more

How to unit-test canActivate guard method of angular2 using Jasmine?

since no one answered my question, so I’m pasting my code snippet for the reference to help people who might get this situation. sampleLoggedIn.guard.ts import {Injectable} from ‘@angular/core’; import {Router, CanActivate} from ‘@angular/router’; import {StorageService} from ‘../storage.service’; @Injectable() export class LoggedInGuard implements CanActivate { constructor(private router: Router, private storageService: StorageService) { } /**Overriding canActivate to … Read more