jasmine

Does jasmine need sinon.js?

孤人 提交于 2019-12-03 09:40:58
I've seen examples on the web in which people use jasmine together with sinon . However, jasmine has support for spies (which as I understand is what Sinon does). So, the question is, is Sinon still useful when using Jasmine ? If Sinon is useful what exactly makes it a good addition to jasmine ? Cheers No you dont need Sinon to work with Jasmine. But Sinon spy/mock/stubs are more convenient in some cases. There is also a minor bug in mocking setTimeout in Jasmine, which work as expected with sinon. I use Sinon with Jasmine for it's fakeServer capabilities. Sinon allows me to easily mock AJAX

Angular testing submit event on reactive form

寵の児 提交于 2019-12-03 09:23:15
Context I have a component with a basic form (reactive form). I try to test the submit event on this form to see if it calls the necessary method properly. My problem I can't trigger the submit event of the form Files Component.html <form class="form-horizontal" id="staticForm" [formGroup]="mySimpleForm" (ngSubmit)="sendMethod();" > <input type="text" formGroupName="email"> <button type="submit">Send form</button> </form> Component.ts ngOnInit() { this.initSimpleForm(); } private initSimpleForm() { let file = null; this.mySimpleForm = this.formBuilder.group({ email: [ '', [ Validators.required

How do I declare a variable in a specific scope in coffeescript?

こ雲淡風輕ζ 提交于 2019-12-03 09:21:11
I'm trying to write a jasmine test in coffeescript that uses a beforeEach block. This runs into a problem with coffeescript's variable scoping. Here's what I'd like to write: describe 'PhoneDetailCtrl', () -> beforeEach () -> scope = angular.scope() $browser = scope.$service('$browser') it 'should fetch phone detail', () -> scope.params = {phoneId:'xyz'} $browser.xhr.expectGET('phones/xyz.json').respond({name:'phone xyz'}) ctrl = scope.$new(PhoneDetailCtrl) expect(ctrl.phone).toEqualData({}) $browser.xhr.flush() expect(ctrl.phone).toEqualData({name:'phone xyz'}) This doesn't work, though,

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

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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

Jasmine Controller test: $timeout.flush() causes an 'Unexpected GET request' error

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have the following test: it ( 'should load productGroups into the scope' , function (){ scope . _section = 'modifiers' ; scope . userData = { method : 'manual' }; scope . $digest (); timeout . flush (); //causes the error expect ( scope . productGroups ). toEqual ( productGroupService . getProductGroups ()); }); Now, the action that I am trying to test occurs within a timeout of 0, because of some issues I had with syncing the data stored in the cookies. Now, without the marked line, the test runs find, except the expected result

Jasmine controller testing, expected spy to have been called

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a method defined in AngularJS controller which is called on initialization. I want to test it using Jasmine ( "jasmine-core": "^2.3.4", "karma": "^0.12.37" ). I follow some tutorials on the Internet and StackOverflow questions, but I cannot find the right answer. Please take a look at this code: Controller usersAddUserController : (function () { 'use strict'; angular.module('app.users.addUser') .controller('usersAddUserController', ['$scope', 'usersAddUserService', function ($scope, usersAddUserService) { usersAddUserService

backbone view - is not defined

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This really confuses me, I think I'm stupid but I've searched and have done whatever I could. Whenever I declare a view and run BDD test with jasmine, it always returns "undefined is not a function". This is code window.LocationView = Backbone.View.extend({ initialize: function() { // create new marker first this.marker = new google.maps.Marker({ title: this.model.get('name'), draggable: true, animation: google.maps.Animation.DROP, position: new google.maps.LatLng(this.model.get('lat'), this.model.get('long')), // give the position here });

Angular Karma Jasmine Error: Illegal state: Could not load the summary for directive

匿名 (未验证) 提交于 2019-12-03 08:35:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm developing a github repository (with angular 4 and angular-cli), and I have some tests with Karma and Jasmine working in the master branch. Now I'm trying to add lazy loading feature, and I've created a new branch that you can see here . The thing is, that the tests that before passed, now they do not. It's funny because only the tests from the lazy loading module are failing... Here is the code and the error: import {async, TestBed} from '@angular/core/testing'; import {APP_BASE_HREF} from '@angular/common'; import {AppModule} from '../

How to mock Angular 4.3 httpClient an error response in testing

ⅰ亾dé卋堺 提交于 2019-12-03 08:27:59
问题 I have a below interceptor auth-interceptor.service.ts import {Injectable, Injector} from '@angular/core'; import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http'; import {Observable} from 'rxjs/Observable'; import {Cookie} from './cookie.service'; import {Router} from '@angular/router'; import {UserService} from './user.service'; import {ToasterService} from '../toaster/toaster.service'; import 'rxjs/add/operator/catch'; import 'rxjs/add

Use jasmine to test Express.js

孤街浪徒 提交于 2019-12-03 08:27:32
问题 I am learning Node.js and Express framework. I am a big fan of jasmine. So I want to use jasmine whenever I can, however, I can't find a good way testing Express with jasmine. For example, how should I test a route in app.js? If I have this route in app.js: app.get('/', function(req, res) { ... }); How can I use jasmine to test it? 回答1: Jasmine-node makes it easy to use jasmine with node.js. There are some examples on their site. Another example can be found from http://blog.drewolson.org