jasmine

Is Jasmine's beforeEach synchronous?

大城市里の小女人 提交于 2019-12-06 05:50:48
问题 If you have multiple beforeEach 's, will they always run one after another? beforeEach(function() {}); beforeEach(function() {}); beforeEach(function() {}); beforeEach(function() {}); beforeEach(function() {}); It seems that they will. I tried testing it with my code: describe('Directive: Statement', function() { var el, scope, statements; beforeEach(module('simulatedSelves')); beforeEach(module('templates')); beforeEach(inject(function($compile, $rootScope) { console.log(1); scope =

Angularjs unit testing resolving promises

蓝咒 提交于 2019-12-06 05:45:01
I'm probably doing this wrong but I can't figure out how to fix it. I want to test a controller that uses a resource (ngResource) and I want to use a Spy as a test double for the resource so it doesn't actually do the http call. In the code below I just want to test the search function in the controller. Controller: controllers = angular.module('app.controllers'); controllers.controller('landingCtrl', ['$scope', '$q', 'categoryResource', function ($scope, $q, categoryResource) { $scope.search = function (text) { console.log('searching for: ' + text); var deferred = $q.defer(); categoryResource

Requiring timeouts when testing Meteor with Velocity and Jasmine

陌路散爱 提交于 2019-12-06 05:22:20
问题 Pretty new to meteor, velocity and jasmine so not sure if I am doing something wrong, using Jasmine for something it's not designed for, or this is just the way it works. I am finding I need to set timeouts for pretty much all of my tests in order to get them to pass. Should this be the case or am I doing something incorrectly? For example some tests I am running to check validation messages: describe("add quote validation", function() { beforeEach(function (done) { Router.go('addQuote');

Angularjs - how to unit test form validation

拥有回忆 提交于 2019-12-06 05:20:59
问题 I'm using Jasmine to unit test my Angular App. How can I test form validation in my controller? For example, I have a login function: $scope.login = function() { if($scope.form_login.$valid) { //send request with username and password }; }; I'm trying to set $valid to true , but I can't access the form here. I got an error TypeError: Cannot set property '$valid' of undefined : it('should not send request if form validation fails', function() { $controller('loginController', {$scope: $scope});

Mocking an angular service in Protractor

假装没事ソ 提交于 2019-12-06 05:20:18
I'm trying to use Protractor's addMockModule to insert mock data in my end-2-end test. My test is supposed to go to a web site, find a button by css-class and click it. The button click calls the function dostuff() in MyService, which fetches data from the backend. My code so far: describe('should display validation error', function () { it('should work', function () { browser.get('http://my.url'); browser.addMockModule('MyService', function () { // Fake Service Implementation returning a promise angular.module('MyService', []) .value({ dostuff: function () { return { then: function (callback)

Protractor - Jasmine - Download file to a relative path

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 04:57:36
I've read and follow the below questions here and its comments/answers: Question 1 Question 2 Question 3 But could not find a way not to use absolutePath , since I need to have this tests run on another machine, so, I need to be relative to the project no the other folder outside of it. how can I accomplish that? As explained in the questions you have quoted, You can control where the file downloads using the below option 'chromeOptions': { prefs: { download: { 'prompt_for_download': false, 'default_directory': <<absolutePath>> } } } Coming to your question on how to accomplish this when

Mocking $routeParams in a test in order to change its attributes dynamically

三世轮回 提交于 2019-12-06 04:50:50
问题 I have a controller test that depends on the Angular $routeParams service: var $routeParams, MainCtrl, scope; beforeEach(inject(function ($controller, $rootScope, $injector, $templateCache) { scope = $rootScope.$new(); $routeParams = $injector.get('$routeParamsMock'); MainCtrl = $controller('MainCtrl', { $scope: scope, $routeParams: $routeParams, }); })); it('should load a pg from $routeParams', function(){ scope.userData = {}; $routeParams._setPg('PG_FIRST'); scope.$digest(); timeout.flush()

How to reset knockout bindings in Jasmine test

ぐ巨炮叔叔 提交于 2019-12-06 04:21:15
I'm trying to write test for knockout feature with jasmine as below and I'm getting following error: Error: You cannot apply bindings multiple times to the same element. describe("ThreeStepNavigationView", ()=> { var testSubject; var SmallNavigationStates = ['ribbon','expanded']; var ExtraSmallNavigationStates = ['collapsed','ribbon','expanded']; beforeEach(()=> { loadFixtures('SidebarAndSiteHeader.html'); testSubject = new Mobile.Navigation.ThreeStepNavigation.View(); ko.applyBindings(testSubject); }); describe('When user clicks on navigation toggle button', ()=>{ it('Should update state

Testing a service function POST response with Jasmine

两盒软妹~` 提交于 2019-12-06 04:15:53
I'm not entirely sure how to do this but I have a endpoint URL which is a POST request for login authentication. When you add a request payload, you will get either a successful login credential or an error. However, I seem to have problems with fetching the response. Here is my spec file: describe('Service: AuthFactory',function(){ beforeEach(function () { module('ui.router'); module('users'); module('main'); }); var AuthFactory, httpBackend; beforeEach(inject(function($httpBackend, $rootScope, $controller, _AuthFactory_){ httpBackend = $httpBackend; AuthFactory = _AuthFactory_; })); it(

karma/jasmine console more detailed test results

给你一囗甜甜゛ 提交于 2019-12-06 03:53:38
I'm using Karma with Jasmine for my javascript unit tests. Suppose I have a failing test like this: expect(objectA).toEqual(expectedObjectA); When it fails, I see the two objects dumped on the console and a message telling me the objects are not equal: This is not very helpful because in order to find out why they are not equal, I have to to copy paste the text from the console, split the two objects from that object dump, format them, put them in a diff editor. (Sometimes even that doesn't help because the object are not equal because they have members which are functions). Is there a way to