jasmine

AngularJs unit testing memory leaks

前提是你 提交于 2019-12-29 02:44:50
问题 as you may already know many of us who have a large quantity of written unit test has met with this not trivially solvable problem. I have around 3500+ unit tests written in the Jasmine syntax following the AngularJs unit testing guide. The tests are executed with Karma runner. The problem is that they cannot be executed all at once due to some memory leaks. While running them the memory builds up no matter on what browser they are runned on and at some point the browser crashes and

How to deal with angular module's config function when unit testing?

别等时光非礼了梦想. 提交于 2019-12-28 15:11:49
问题 When setting up a unit test suite for an angular application using Karma/Jasmine, is it recommended to include the js with the app module's config function in the test's files? I've read that it is suggested to exclude this from testing, however that seems awkward because there's often critical setup that happens in the config function that would prevent the application from working. What's the best practice around this? Create a mock config function that does the same thing in a 'mocked'

How to deal with angular module's config function when unit testing?

╄→尐↘猪︶ㄣ 提交于 2019-12-28 15:09:27
问题 When setting up a unit test suite for an angular application using Karma/Jasmine, is it recommended to include the js with the app module's config function in the test's files? I've read that it is suggested to exclude this from testing, however that seems awkward because there's often critical setup that happens in the config function that would prevent the application from working. What's the best practice around this? Create a mock config function that does the same thing in a 'mocked'

How do I assert an element is focused?

谁说胖子不能爱 提交于 2019-12-28 13:21:10
问题 I am attempting to verify that the focused element is set on page load as one of my tests. This seems to be working, and I can verify with the element explorer, but the Jasmine matchers don't seem to pick up on this. Here's my code: var LoginPage = function () { this.basePath = browser.params.baseUrl; this.loginPart = "/#/login"; this.usernameInput = element(by.model('username')); this.get = function () { ... } } it('should focus on the username field on load', function () { loginPage.get();

Unit testing in AngularJS - Mocking Services and Promises

Deadly 提交于 2019-12-28 11:55:14
问题 In Angular everything seems to have a steep learning curve and unit testing an Angular app definitely doesn't escape this paradigm. When I started with TDD and Angular I felt that I was spending twice (maybe more) as much time figuring out just how to test and maybe even more just getting my tests set up correctly. But as Ben Nadel put it in his blog there are ups and downs in the angular learning process. His graph is definitely my experience with Angular. However as I have progressed in

Unit testing in AngularJS - Mocking Services and Promises

痞子三分冷 提交于 2019-12-28 11:55:07
问题 In Angular everything seems to have a steep learning curve and unit testing an Angular app definitely doesn't escape this paradigm. When I started with TDD and Angular I felt that I was spending twice (maybe more) as much time figuring out just how to test and maybe even more just getting my tests set up correctly. But as Ben Nadel put it in his blog there are ups and downs in the angular learning process. His graph is definitely my experience with Angular. However as I have progressed in

Unit Testing a Service That Uses AngularFireAuth and Mocking authState

回眸只為那壹抹淺笑 提交于 2019-12-28 06:51:32
问题 I have been going round in circles trying to unit test a Service ( AuthService ) that depends upon AngularFireAuth . I am trying to find a way to mock, or highjack the Observable AngularFireAuth.authState instead of the Service actually talking to Firebase. Here is my test spec: import { inject, TestBed } from '@angular/core/testing'; import { AngularFireModule } from 'angularfire2'; import { AngularFireAuth, AngularFireAuthModule } from 'angularfire2/auth'; import * as firebase from

Does Jasmine's toThrow matcher require the argument to be wrapped in an anonymous function?

不羁岁月 提交于 2019-12-28 05:36:08
问题 The documentation at https://github.com/pivotal/jasmine/wiki/Matchers includes the following: expect(function(){fn();}).toThrow(e); As discussed in this question, the following does not work because we want to pass a function object to expect rather than the result of calling fn() expect(fn()).toThrow(e); Question 1: Does the following work? expect(fn).toThrow(e); Question 2: If I've defined an object thing with a method doIt , does the following work? expect(thing.doIt).toThrow(e); (2a: if

Stop jasmine test after first expect fails

耗尽温柔 提交于 2019-12-28 03:04:52
问题 I'm familiar with python unittest tests where if an assertion fails, that test is marked as "failed" and it moves on to other tests. Jasmine on the other hand will continue through all expects even if the one of them fails. How can I make Jasmine stop processing a test after the first expectation fails? it ("shouldn't need to test other expects if the first fails", function() { expect(array.length).toBe(1); // don't need to check this if the first failed. expect(array[0]).toBe("foo"); }); Am

Using Jasmine to spy on a function without an object

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-27 17:09:14
问题 I'm new to Jasmine and have just started using it. I have a library js file with lots of functions which are not associated with any object (i.e. are global). How do I go about spying on these functions? I tried using window/document as the object, but the spy did not work even though the function was called. I also tried wrapping it in a fake object as follows : var fakeElement = {}; fakeElement.fakeMethod = myFunctionName; spyOn(fakeElement, "fakeMethod"); and test with expect(fakeElement