jasmine

How to load mock data from JSON file in Angular 2 karma jasmine test?

你离开我真会死。 提交于 2019-12-05 21:43:54
问题 I writing karma jasmine test case for angular 2 , And we came across requirement to mock data in separate JSON file as data is huge (want to make sure code cleanness). For this I searched a lot but didn't find proper solution. We already mocking HTTP service using MockBackend , So we can't use HTTP service of angular to load JSON as it eventually request will go to MockBackend. So is there any another way without using any third party lib like jasmine-jquery or Karma-jasmine-preprocessor ?

protractor: test download file without knowing filename

微笑、不失礼 提交于 2019-12-05 21:39:48
问题 I followed this answer and it looks almost the thing I need. The problem there is that he already knows the filename and I am doing e2e test for downloading a file, but the filename depends on the current time (even with milliseconds) so I don't really know the name (or it would be very difficult to get it). I think I am missing something very simple here, but I was thinking of two ways: Recreate filenames (with the same function that returns the name of this file) and start checking for

Protractor/Jasmine drag and drop only grabbing text not the element

时光怂恿深爱的人放手 提交于 2019-12-05 21:28:23
I have a Protractor/Jasmine E2E Automation test that is to drag and drop a couple of collapsible panels to change the order and just verify they the elements have been moved. I'm currently running latest versions of Protractor, Jasmine, and webdrivers (tests run in IE 11) EDIT: Found out we're using ng-dragula to perform the drag and drops. I'm assuming protractor just isn't playing nicely with this. I'll do more digging about it, but still curious to know if there's a work around. /end edit This function used to work, and I have since tried a handful of variations of it: browser.actions().

Testing postMessage with Jasmine async doesn't work

社会主义新天地 提交于 2019-12-05 21:08:07
问题 I'm trying to use Jasmine 2.0 to write unit tests for some logic in an AngularJS app, but the logic is inside an event listener. From the controller: window.addEventListener('message', function(e) { if (e.data === "sendMessage()") { $scope.submit(); } }, false); And from the test file: describe("post message", function() { beforeEach(function(done) { var controller = createController(controllerParams); spyOn($scope, 'submit'); window.postMessage('sendMessage()', '*'); done(); }); it('should

Angular unit testing: how to test controller properties without scope

让人想犯罪 __ 提交于 2019-12-05 21:00:45
I'm trying to write some tests for a controller, but ALL the documentation/tutorials/etc on this demonstrate with functions and variables on $scope. What if you want to test something NOT on $scope? Ex: app.controller('fakeCtrl', function($scope) { var foo = 'bar'; function fooBar() { console.log('foo bar'); } }); Is there any way to unit test foo or fooBar() ? Here's what DOESN'T work: describe("fake controller", function(){ beforeEach(module('app')); var $controller; beforeEach(inject(function(_$controller_, $rootScope){ $controller = _$controller_; $scope = $rootScope.$new(); })); describe(

Jasmine Unit Test Abstract class

元气小坏坏 提交于 2019-12-05 20:54:08
问题 Is there a way to create a jasmine unit test for an abstract component? doing const fixture = TestBed.createComponent(MyAbstractComponent); says, "cannot assign an abstract constructor type to a non-abstract constructor type" I tried some searching but nothing comes up. 回答1: You can create a simple class in your test file which extends from abstract class (do not forget to mock abstract methods), than just test its non abstract methods. Let's say we have MyAbstractClass : export abstract

Module not found error in AngularJS unit test

穿精又带淫゛_ 提交于 2019-12-05 20:45:01
I'm trying a very simple test with Karma/Jasmine, to unit test my AngularJS app. This seems to work beforeEach( module('myApp') ); it('should blah', function () { expect(true).toBe(true); }); while this doesnt beforeEach( function () { module('myApp') } ); it('should blah', function () { expect(true).toBe(true); }); I want to be able to do other stuff beforeEach test suite, but it's not giving me any meaningful errors to be able to debug it, the only one I see is TypeError: 'undefined' is not an object (evaluating 'currentSpec.queue.running') relating to the line where the function is called

Running Jasmine Integration Tests in Parallel via Selenium Grid

与世无争的帅哥 提交于 2019-12-05 19:59:40
I've playing around with jasmine and selenium webdriver for browser automation via node.js. What do I need to configure in order to run tests in parallel? I understand that on a java stack TestNG is often used to run parallel tests, what would be the best tool or configuration to run parallel selenium tests using jasmine and node.js? 来源: https://stackoverflow.com/questions/32211695/running-jasmine-integration-tests-in-parallel-via-selenium-grid

angular + jasmine + mock $stateParams in a directive

烈酒焚心 提交于 2019-12-05 19:45:23
What is the best approach to mock $stateParams in a directive? $stateParam members will be changed according to the test. I can easily mock $stateParams in a controller using $controller('ctrl', $stateParams) but dont know how to modify $stateParams that gets injected into the directive. I've gone the route of decorating $stateParams with the below but can only declare that when i create the module. as i mentioned, $stateParam members will change many times through the different tests. beforeEach(angular.mock.module(function ($provide) { $provide.provider('$stateParams', function () { return {

How to inject controller dependencies in Jasmine tests?

六眼飞鱼酱① 提交于 2019-12-05 19:41:11
There is the following controller definition: angular.module('app.controllers', []).controller('HomeController', [ '$scope', '$modal', 'Point', function($scope, $modal, Point) { //some action } I want to test this controller: describe('HomeController', function() { beforeEach(module('app.controllers')); var $controller; beforeEach(inject(function(_$controller_){ // The injector unwraps the underscores (_) from around the parameter names when matching $controller = _$controller_; })); describe('$scope.grade', function() { it('sets the strength to "strong" if the password length is >8 chars',