jasmine

AngularJs unit test - Check if “Init” function was called

爱⌒轻易说出口 提交于 2019-12-11 01:52:51
问题 I'm using jasmine as testframework and I've the following Controller I want to test. And I allways have a Init() function where I place my initialization calls for this Controller. Now I want to test if the Init function was called when the controller was initialized. function UnitTestsCtrl() { var that = this; this.Init(); } UnitTestsCtrl.prototype.Init = function() { var that = this; //Some more Stuff } angular.module("unitTestsCtrl", []) .controller("unitTestsCtrl", UnitTestsCtrl); But I

$compile not compiling templates in Karma/Jasmine

前提是你 提交于 2019-12-11 01:45:43
问题 I have tested this with both PhantomJS and Chrome. Following this question I'm trying to get access to the generated HTML code in unit tests with Karma: it('Should do something', inject(function ($rootScope, $templateCache, $compile) { var scope = $rootScope.$new(); scope.$digest(); var template = $templateCache.get('/app/views/mytemplate.html'); var compiler = $compile(template); var compiledTemplate = compiler(scope); console.log(compiledTemplate); })); What I've found is that template is

Can't spy on an event handler even though I can spy on other methods

寵の児 提交于 2019-12-11 01:07:22
问题 I want to test an event handler in React using Jest/Jasmine/Enzyme. MyComponent.js : import React from 'react'; class MyComponent extends React.Component { constructor(props) { super(props); this.clickHandler = this.clickHandler.bind(this); this.otherMethod = this.otherMethod .bind(this); } clickHandler() { this.otherMethod(); } otherMethod() {} render() { return <div onClick={this.clickHandler}/>; } } export default MyComponent; MyComponent.test.js : import React from 'react'; import {mount}

How to test focus in AngularJS?

孤者浪人 提交于 2019-12-11 01:02:48
问题 Consider the following skFocus service: angular.module('sk.focus', []).service('skFocus', function($timeout) { return function(cssSelector) { $timeout(function() { var element = document.querySelectorAll(cssSelector); if (element.length > 0) { element[0].focus(); } }, 100); }; }); I'm trying to create a test for this service: describe('Service: skFocus', function() { beforeEach(module('sk.focus')); var $window, $timeout, skFocus; beforeEach(inject(function(_$window_, _$timeout_, _skFocus_) {

how to test $http call in angular js?

一个人想着一个人 提交于 2019-12-11 00:53:57
问题 I am trying to test my $http request using karma and jasmine.I make one controller and inject a service .In service I call $http service.I need to test that service how I will test this service this is my controller. angular.module('app',[]).controller('first',function($scope,data){ $scope.name='test'; data.getData().then(function(data){ console.log(data); }) }).factory('data',function($http){ return{ getData:getData } function getData(){ return $http.get('data.json').success(successCall)

BDD cycle - how to join backend with frontend

大城市里の小女人 提交于 2019-12-10 23:55:38
问题 I'd like to know how you connect frontend BDD (i.e. Jasmine) with backend BDD (rspec, cucumber). How these two relate and form one cohesive BDD cycle? What would be the correct steps of this cycle? 回答1: To create a cohesive BDD cycle you would use the "outside-in" development technique, and then take the approach of "faking it until you make it" i.e. using mock objects until you write concrete implementations. Lets say you have the following cucumber scenario: Given I am on the home screen

Controller undeclared in Jasmine test

情到浓时终转凉″ 提交于 2019-12-10 23:38:21
问题 I have a following code for Jasmine testing. ProjectConfigurationCtrl is the name of controller I am trying to test. describe('Unit test: ProjectConfiguration controller', function() { var scope, routeParams, infraService, controllerToTest; // some stuff declaration skipped... beforeEach(inject(function($injector) { // get all dependences routeParams = $injector.get('$routeParams'); infraService = $injector.get('InfraService'); $rootScope = $injector.get('$rootScope'); scope = $rootScope.$new

AngularJS Jasmine test: TypeError: 'undefined' is not an object

♀尐吖头ヾ 提交于 2019-12-10 23:28:50
问题 New to Angular and following up from my earlier post from angularjs jasmine tests: Variable vm not found I am having a TypeError in my angular tests and not sure what the problem is. Here is my test: (function(){ 'use strict'; describe('Testing DeliveriesController', function() { beforeEach(module('app.deliveries')); describe('Testing deliveries controller', function(){ var vm, controller; beforeEach(inject(function($controller, $rootScope){ vm = $rootScope.$new(); controller = $controller(

How do you mock an angularjs $resource factory

倖福魔咒の 提交于 2019-12-10 23:19:34
问题 I have a resource factory angular.module('mean.clusters').factory('Clusters', ['$resource', function($resource) { return $resource('clusters/:clusterId/:action', { clusterId: '@_id' }, { update: {method: 'PUT'}, status: {method: 'GET', params: {action:'status'}} }); }]); and a controller angular.module('mean.clusters').controller('ClustersController', ['$scope', '$location', 'Clusters', function ($scope, $location, Clusters) { $scope.create = function () { var cluster = new Clusters();

confuse about the execution order of nested testing suite and specs

北慕城南 提交于 2019-12-10 23:13:27
问题 All: I just start the second day study about Jasmine, there is one question about exe order I want to figure out: This example is from Jasmine 2.0 introduction: Jasmine 2.0 Introduction describe("Asynchronous specs", function() { var value; beforeEach(function(done) { setTimeout(function() { value = 0; done(); }, 1); }); it("should support async execution of test preparation and expectations", function(done) { value++; expect(value).toBeGreaterThan(0); done(); }); describe("long asynchronous