jasmine

Insert(SpyOn 2 times) jQuery value to input during Jasmine tests

倖福魔咒の 提交于 2020-01-17 06:35:11
问题 Hi i have a works tests it("should add a model", function() { spyOn($.fn, "val").and.returnValue("Bar"); foodtype.addNewFoodtype(); //My view expect($("#newFoodtype").val()).toEqual("Bar"); expect(foodtype.collection.length).toEqual(1); }); on next test when I set spyOn($.fn, "val").and.returnValue("Bar"); $("#newFoodtype").val() spyOn($.fn, "val").and.returnValue("Foo"); $("#newFoodtype").val() to checking a change but have a error Error: spyOn : val has already been spied upon Usage: spyOn

How to include one CoffeeScript file in another in order to share specs amongst jasmine

a 夏天 提交于 2020-01-17 05:24:16
问题 I'm unable to get CoffeeScript in Jasmine to include another file. I'd like to share common functions amongst Jasmine specs which are written in CoffeeScript. I'm sure I'm getting the syntax wrong, I've tried require and include , I've tried putting the file in the same folder just to be sure, I've tried # = syntax too. I'm looking for something similar to include in php, i.e. go here -> compile this -> come back so the compile this step can easily be shared. NB, I am not talking about

Jasmine - How to test a stylesheet directive

岁酱吖の 提交于 2020-01-16 20:36:16
问题 I have written a directive that interrogates the current URL, and loads the corresponding freestyle. The problem i am facing is how can i test the link function: HTML: <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8"> <title>CSS Test</title> <link get-style-directive /> </head> Directive: app.directive('getStyleDirective', ["$compile", "$location", function($compile, $location) { return { replace: true, scope: true, link: function(scope, element, attrs) { var urlValue = $location

form control is always pending in async validator

一曲冷凌霜 提交于 2020-01-16 19:37:14
问题 I have a form control that is as following: .... direction: new Form("", [Validators.pattern("^[0-9]*$")],[requiredAsyncValidator]) and the requiredAsyncValidator is export const requiredAsyncValidator = (control:FormControl):Promise<any> | Observable<any> => { return new Promise<any>((resolve,reject) => { setTimeout(() => { if(control.value == '' && control.touched) { resolve({required:true}) } else{ resolve(null) },100) }) } in my html I have attached (blur)="direction

How to test two returned functions with different argument value in javascript?

亡梦爱人 提交于 2020-01-16 18:00:33
问题 I have a function that returns comparisonFunction getComparisonFunction(propertyOfComparison) { const func = function(a, b){ if ( a[propertyOfComparison] < b[propertyOfComparison] ) { return -1; } if ( a[propertyOfComparison] > b[propertyOfComparison] ) { return 1; } return 0; }; return func; } This method will be used inside javascript "sort" method. for example: arrayOfObjects.sort(getComparisonFunction('name')); This method will sort "arrayOfObjects" by "name" property. Method works fine,

I can't create filter to extract all elements that i need

喜欢而已 提交于 2020-01-15 14:22:27
问题 I get prices, even that I don't need, how can I filter them? <div class="ssl-price-box"> <price value="377" units="/yr" class="lg-price ng-isolate-scope"><span class="price"><span class="currency-icon">$</span><span class="integer ng-binding">3.</span><span class="cent ng-binding">77</span><span class="units">/yr</span></span></price> <!-- ngIf: product.prices.max.certIsPromo --> </div> <price value="13888" units="/yr" class="lg-price ng-isolate-scope"> <span class="price"> <span class=

Angular2: How to test a component function that sometimes returns, sometimes routes?

允我心安 提交于 2020-01-15 10:22:21
问题 I'm still developing an app based on the Angular2 Heroes tutorial. At this point I have a component where the user makes an edit, clicks on Save and on success the user is spirited to the parent page (route "../"). If there is an error in saving then the routing doesn't occur, and the page displays the error information. The spiriting occurs in the component's save function: private gotoParent(): void { this.router.navigate(['../'], { relativeTo: this.route }); } public save(): void { this

Angular2: How to test a component function that sometimes returns, sometimes routes?

一世执手 提交于 2020-01-15 10:19:15
问题 I'm still developing an app based on the Angular2 Heroes tutorial. At this point I have a component where the user makes an edit, clicks on Save and on success the user is spirited to the parent page (route "../"). If there is an error in saving then the routing doesn't occur, and the page displays the error information. The spiriting occurs in the component's save function: private gotoParent(): void { this.router.navigate(['../'], { relativeTo: this.route }); } public save(): void { this

How to unit test custom decorator with Jasmine (Angular js)

流过昼夜 提交于 2020-01-15 06:18:22
问题 So I have such decorator in app config: angular.module('app').config(['$provide', function ($provide) { $provide.decorator('$rootScope', ['$delegate', function ($delegate) { $delegate.constructor.prototype.$onRootScope = function (name, listener) { var unsubscribe = $delegate.$on(name, listener); this.$on('$destroy', unsubscribe); }; $delegate.constructor.prototype.$watchRootScope = function (name, listener) { var unsubscribe = $delegate.$watch(name, listener); this.$on('$destroy',

Spy on Backbone.js View Functions with Jasmine

青春壹個敷衍的年華 提交于 2020-01-15 05:48:05
问题 I'm trying to write a Jasmine spec to verify that a view's function is called when a model is added to the view's collection. In the view's initialize function I do this.collection.on('add', this.fooAdded, this); In my Jasmine spec I'm doing: describe('Foo View', function() { it('should call fooAdded when a Foo is added', function() { var view = new FooView({collection: new FooCollection()}); spyOn(view, 'fooAdded').andCallThrough(); view.delegateEvents(); view.collection.add({name: 'foo'});