jasmine

Executing Typescript Jasmine tests via Webpack (Terminal) to test Angular2

*爱你&永不变心* 提交于 2019-12-07 09:21:25
问题 Currently I'm trying to get Jasmine to run along with Webpack, to execute tests written in typescript to test Angular2 Apps in the Terminal. I researched yesterday which packages are available for testing, and while angular2 has their own approach *1 , I looked for other tools than the recommended jasmine-core or jasmines native package jasmine . I found jasmine-node which is outdated for 2 years now. Currently investigating the Webpack+Angular2 with Jasmine testing package *2 After reading

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

时光总嘲笑我的痴心妄想 提交于 2019-12-07 08:52:25
问题 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

Jasmine: Unit test http service error observable

柔情痞子 提交于 2019-12-07 08:45:56
问题 I am pretty confused on how to mock that my http service catches an observable error. I have read through the angular documentation but I do not understand how I would structure the test. I would like to mock an error in my service, then check that it catches an error observable. I have another service that creates and throws the error observable. The rest of my services just catch it when encountering an error. I am honestly very confused on how to implement this. Here is a simple verison of

How do I spy on an Angular promise chain using Jasmine

只愿长相守 提交于 2019-12-07 08:39:06
问题 Using AngularJS, CoffeeScript and Jasmine (edited in WebStorm), I would like to unit test a chain of promises. Lets say I have the following example service: Angular Service class ExampleService stepData: [] constructor: (@$http) -> attachScopeMethod: (@scope) -> @scope.callSteps = => @step1().then -> @step2() step1: -> @$http.get('app/step/1').then (results) => @stepData[0] = results.data results step2: -> @$http.get('app/step/2').then (results) => @stepData[2] = results.data results This

AngularJS Protractor - How Do You Test an AJAX Login Call?

大兔子大兔子 提交于 2019-12-07 08:25:17
问题 I have a button that once clicked sends out an AJAX call in Angular's $promise format. When the login is successful, a $scope variable is changed and an element that looks like: <section id="logged-in-section" ng-if="auth.user !== null"> // Section to display if logged in </section> is displayed. I am currently testing the above with the following: loginButton.click(); browser.sleep(2000); expect($("#logged-in-section").isDisplayed()).toBeTruthy(); browser.sleep(2000) idles the browser for

Protractor E2E Testing Error : Object [object Object] has no method 'getWindowHandle'

心不动则不痛 提交于 2019-12-07 07:41:50
问题 I am trying to check the pop up for facebook login opening on click of button . Error : Object [object Object] has no method 'getWindowHandle'. Code Snippet generating error : describe('Tests', function() { var ptor; var handlePromise; var util = require('util'); beforeEach(function() { ptor = protractor.getInstance(); handlePromise = ptor.getAllWindowHandles(); var handlesDone = false; ptor.get('/SiteB_Upgrade_Device/app/index.html#/Recommendations#page'); ptor.findElement(by.id('fb')).click

Unit test code of web worker

安稳与你 提交于 2019-12-07 07:16:39
问题 Taking the example code from https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/basic_usage , the following is run by a web worker // in worker.js onmessage = function(e) { console.log('Message received from main script'); var workerResult = 'Result: ' + (e.data[0] * e.data[1]); console.log('Posting message back to main script'); postMessage(workerResult); } run by code in an Angular service/factory var myWorker = new Worker("worker.js"); I would like to be able to unit test the

How to you test an angularjs module defined inside an IIFE with jasmine?

余生颓废 提交于 2019-12-07 07:09:58
问题 how do I test this module on jasmine ? The problem is that it's very difficult to test the $controller because the function is hidden inside a closure, it’s very difficult to test them. In other words, given the module definition below, writing a unit test for MainCtrl seems impossible. (function () { 'use strict'; angular.module('app', []); function MainCtrl() { var mc = this; mc.obj = { val : 50 }; } angular.module('app').controller('MainCtrl', MainCtrl); } () ); and the "typical" jasmine

Assert arrays in Protractor

夙愿已清 提交于 2019-12-07 06:58:06
问题 I am working on E2E tests and my goal is to compare two arrays. I set these arrays so that they are identical. The problem is that Protractor doesn't think they are same. My code: expect(arrPuv).toBe(arrNov); Console output: Error: Expected [ '1 patro', '2. Patro', 'asdf', 'My precious', 'My precious', 'My precious', 'My precious' ] to be [ '1 patro', '2. Patro', 'asdf', 'My precious', 'My precious', 'My precious', 'My precious' ]. How can I compare them correctly? 回答1: This actually goes

Expected '> ' to equal '> ' in jasmine

耗尽温柔 提交于 2019-12-07 06:15:46
问题 I'm testing jQuery terminal and I got error: Expected '> ' to equal '> '. when testing: $(function() { describe('Terminal plugin', function() { describe('terminal create terminal destroy', function() { var term = $('<div id="term"></div>').appendTo('body').terminal(); it('should have default prompt', function() { var prompt = term.find('.prompt'); expect(prompt.html()).toEqual("<span>> </span>"); expect(prompt.text()).toEqual('> '); }); }); }); }); they are same value I just copy it into