karma-jasmine

AngularJS - How to test if a function is called from within another function?

痞子三分冷 提交于 2019-11-30 23:07:53
问题 I'm trying to get started with karma-jasmine and I'm wondering why this test fails: it("should call fakeFunction", function() { spyOn(controller, 'addNew'); spyOn(controller, 'fakeFunction'); controller.addNew(); expect(controller.fakeFunction).toHaveBeenCalled(); }); In my controller that I've previously set up for this test I have the following: function addNew() { fakeFunction(3); } function fakeFunction(number) { return number; } both addNew and fakeFunction are exposed using: vm.addNew =

karma + Chrome not working after last auto-update of Chrome

[亡魂溺海] 提交于 2019-11-30 22:32:43
问题 We use jenkins with a number of jenkins slave nodes running on Windows 7. Through jenkins we kick off karma tests to be run on the slave node to run our jasmine tests on the actual browsers. Suddenly last week after Chrome auto-updated to version "38.0.2125.104 m" this stopped working (karma unable to capture the browser). Here are our logs: [INFO] --- maven-karma-plugin:1.8:start (default-cli) @ module-translation --- [INFO] Executing Karma Test Suite ... [INFO] cmd /C karma start C:\dev

Can't bind to 'matMenuTriggerFor' since it isn't a known property of 'button'

我们两清 提交于 2019-11-30 22:20:10
问题 I'm getting following error when I try to test an angular component: Error while running jest tests: Can't bind to 'matMenuTriggerFor' since it isn't a known property of 'button'. Here is my html: <button mat-button [matMenuTriggerFor]="menu">Menu</button> <mat-menu #menu="matMenu"> <button mat-menu-item>Item 1</button> <button mat-menu-item>Item 2</button> </mat-menu>` I'm using "@angular/material": "6.1.0", in my package.json. I've also imported all the required material dependencies in the

Unit Testing/mocking Window properties in Angular2 (TypeScript)

穿精又带淫゛_ 提交于 2019-11-30 17:34:47
I'm building some unit tests for a service in Angular2. Within my Service I have the following code: var hash: string; hash = this.window.location.hash; However when I run a test which contains this code, it will fail. It'd be great to utilise all the features of Window, but as I'm using PhantomJs, I don't think this is possible (I have also tried Chrome which yields the same results). In AngularJs, I would have resorted to mocking $Window (or at least the properties in question), but as there is not a lot of documentation for Angular2 unit testing I'm not sure how to do this. Can anyone help?

How to get Jasmine's spyOnProperty to work?

谁说我不能喝 提交于 2019-11-30 17:24:43
I saw this post post and was excited to try it out, but I'm unable to get it working. Trying to keep this simple just to figure out what's wrong, but even this is failing. export class SomeService { ... private _myValue: Boolean = false; get myValue(): Boolean { return this._myValue; } set myValue(helper: Boolean) { this._myValue = helper; } And in my unit test, I have: it('should ', inject([SomeService], (someService: SomeService) => { let oldValue = someService.myValue; expect(oldValue).toBe(false); // passes, clearly we can use our getter someService.myValue = true; expect(someService

Angular 4 Error: No provider for ChildrenOutletContexts in Karma-Jasmine Test

不打扰是莪最后的温柔 提交于 2019-11-30 13:12:42
问题 My Angular application is working properly, but I am keep getting Karma error when I run ng test command. I have attached app component, spec, module and html along with package.json file. Error looks like this: Failed: No provider for ChildrenOutletContexts! Error: No provider for ChildrenOutletContexts! at injectionError (http://localhost:9876/_karma_webpack_/vendor.bundle.js:39523:90) at noProviderError (http://localhost:9876/_karma_webpack_/vendor.bundle.js:39561:12) at ReflectiveInjector

jasmine test fails with undefined is not a function(evaluating $browser.$$checkUrlChange())

╄→гoц情女王★ 提交于 2019-11-30 13:11:28
问题 I have a following controller: .controller('ProjectUserAddCtrl', ['$scope', 'ProjectUser', '$q', 'i18nNotifications', function($scope, ProjectUser, $q, i18nNotifications) { var buildUnassignedUsers = function(users, project) { var unassignedUsers = []; angular.forEach(users, function(user) { var match; angular.forEach(project.projectUsers, function(projectUser) { if(match) {return;} if(projectUser.user.id === user.id) { match = true; } }); if(!match) { unassignedUsers.push(user); } }); $scope

Angular testing how to prevent ngOnInit call to test a method directly

瘦欲@ 提交于 2019-11-30 11:27:27
问题 Context I have a component. Inside of it, the ngOnInit function calls another function of component to retrieve user List. I want to make two series of tets: First test the ngOnInit is triggered properly and populate the user list In a second time I want to test my refresh function which also call getUserList() The first test, with ngOnInit trigger, when I call fixture.detectChanges() works properly. Problem My problem is when testing the refresh function: as soon as I call fixture

How to test John papa vm.model unit testing with jasmine?

允我心安 提交于 2019-11-30 11:17:19
I use John papa angular style guide my controller looks like: following the style John papa style controller style guide : function testController() { var vm = this; vm.model = { name: "controllerAs vm test" }; } My testing code looks like: describe('Controller: testController', function () { beforeEach(module('myApp')); var testController; beforeEach(inject(function ($controller) { scope = {}; testController = $controller('testController', { }); })); it('should have vm.model defined and testController.vm.model is equal to controllerAs vm test', function () { expect(testController.vm)

Get json file for karma unit test

瘦欲@ 提交于 2019-11-30 09:07:05
问题 I want to get a JSON file in my unit test because I need to have it for my tests but I dont know how I can include the file I run my test with karma and Jasmine. And my project is created with Angular 2. The name of my JSON file is 'www/assets/mocks/emptyCalendarData.JSON' . Does someone know how I can include a JSON file into a spec file? Thanks UPDATE I tried to use HTTP get but then I got a system let calendarData: Calendar; http.get('www/assets/mocks/emptyCalendarData.json') .map(res =>