jasmine

Jasmine Test in Angular for controller

梦想的初衷 提交于 2020-01-04 02:03:08
问题 I get the following error: TypeError: undefined is not a function The problem is that the common is module and a factory and the problem is on my line var ctrl = $controllerConstructor("resetPasswordSentScreen", { $scope: scope, common: common}); Here is the full test: describe('resetPasswordSentScreen', function () { var scope, $controllerConstructor; beforeEach(module('common', 'app')); beforeEach(inject(function($controller, $rootScope) { scope = $rootScope.$new(); $controllerConstructor =

How to stub Backbone View instantiated within another Views render method when Using RequireJS (and Jasmine / Sinon)

Deadly 提交于 2020-01-03 16:48:35
问题 I am attempting to write unit tests using Jasmine and Sion but I am struggling to find the equivalent of the following when using RequireJs to load modules: sinon.stub(window, "MyItemView"); When using RequireJs, I am unable to stub this way as MyItemView is not attached to the window. The following is an example of when I need stub the MyItemView: var MyView = Backbone.View.extend({ el: '#myElement', initialize : function() { var that = this; this.collection.fetch({ success : function() {

Jasmine.js Testing - spy on window.navigator.userAgent

落爺英雄遲暮 提交于 2020-01-03 16:38:11
问题 I need to find the way to change userAgent value. I tried to spyOn the window.navigator.userAgent . But that's not helping. JS : @Injectable() export class DetectBrowserService { browserIE: boolean; constructor() { this.browserIE = this.detectExplorer(); } public detectExplorer() { const brows = window.navigator.userAgent; const msie = brows.indexOf('MSIE '); if (msie > 0) { // IE 10 or older => return version number return true; } } } Spec : it('should test window.navigator.userAgent', () =>

Jasmine.js Testing - spy on window.navigator.userAgent

末鹿安然 提交于 2020-01-03 16:37:26
问题 I need to find the way to change userAgent value. I tried to spyOn the window.navigator.userAgent . But that's not helping. JS : @Injectable() export class DetectBrowserService { browserIE: boolean; constructor() { this.browserIE = this.detectExplorer(); } public detectExplorer() { const brows = window.navigator.userAgent; const msie = brows.indexOf('MSIE '); if (msie > 0) { // IE 10 or older => return version number return true; } } } Spec : it('should test window.navigator.userAgent', () =>

How to use multiple expect in jasmine

僤鯓⒐⒋嵵緔 提交于 2020-01-03 16:36:18
问题 I am using jasmine with jasmine-species . I am making a test of search in my site . In search there are multiple criteria a user can select . I want to know that how to expect with multiple criteria. Suppose this is my case expect(variable1).toEqual(''); expect(variable2).toEqual(''); expect(variable3).toEqual(''); expect(variable4).toEqual(''); My question is that i want to move all expects into single expect . Is this possible in jasmine ? if yes , then how ? Thanks in advance 回答1: expect

How to use Jest to test React rendered async data?

霸气de小男生 提交于 2020-01-03 15:36:23
问题 I am using React for render and Jest/Jasmine for test. I have test written using old Jest/Jasmine waitsFor and runs but these are gone now in Jasmine 2 and I am not sure how to replace with new done asyncs. In my code React renders a small page about a user. That page has an AJAX call to fetch user posts. I want to test that user posts have come back nice, and waitsFor was very, very good at this: wait until user has some post, then continue. I looked online at lots of people talking about

DEPRECATION:', 'Setting specFilter directly on Env is deprecated, please use the specFilter option in configure'

梦想的初衷 提交于 2020-01-03 11:28:10
问题 I'm using karma + jasmine in my angular 6 application and I'm receiving the following warining: DEPRECATION:', 'Setting specFilter directly on Env is deprecated, please use the specFilter option in configure' What should I do to make solve this warning? 回答1: I was using the version 1.1.1 of karma-jasmine package. Reading this post, I updated it to version 2.0.1 and the warning disappeared. 来源: https://stackoverflow.com/questions/53724061/deprecation-setting-specfilter-directly-on-env-is

Angular test error: Cannot read property 'subscribe' of undefined at new RouterLinkWithHref

南楼画角 提交于 2020-01-03 11:03:51
问题 I don't get what I'm doing wrong, I didn't find any link of RouterLinkWithHref to any error in tests, furthermore I'm not using RouterLinkWithHref anywhere, as far as I know :/ Can anyone help me with this: fdescribe('AddItemComponent: ', () => { let cmp: AddItemComponent; let fixture: ComponentFixture<AddItemComponent>; let de: DebugElement; let el: HTMLElement; const mockRouter = { navigate: jasmine.createSpy('navigate') }; const mockCustomCardService = { getItemDeliveryDate: () =>

Angular test error: Cannot read property 'subscribe' of undefined at new RouterLinkWithHref

冷暖自知 提交于 2020-01-03 11:03:12
问题 I don't get what I'm doing wrong, I didn't find any link of RouterLinkWithHref to any error in tests, furthermore I'm not using RouterLinkWithHref anywhere, as far as I know :/ Can anyone help me with this: fdescribe('AddItemComponent: ', () => { let cmp: AddItemComponent; let fixture: ComponentFixture<AddItemComponent>; let de: DebugElement; let el: HTMLElement; const mockRouter = { navigate: jasmine.createSpy('navigate') }; const mockCustomCardService = { getItemDeliveryDate: () =>

testing an angular checkbox using in jasmin

℡╲_俬逩灬. 提交于 2020-01-03 10:44:54
问题 My situation is as follows: directive scope: { foo:'=' }, template: '<input type="checkbox" ng-model="foo"/>' parent controller $scope.foo = false; jasmine test var cb = iElement.find('input'); $timeout(function() { // using $timeout to ensure $digest() isn't the issue. cb.prop('checked',!cb.prop('checked')) },0); expect(cb.prop('checked')).toBe(true); // passes expect($scope.foo).toBe(true); // doesn't pass My question: why doesn't $scope.foo get updated when I issue the prop('checked') even