jasmine

How to unit test an angularjs promise chain using $httpBackend

不羁岁月 提交于 2020-01-01 02:29:12
问题 Using AngularJS, I am trying to unit test a function that makes multiple calls to $http. My test looks something like this: it('traverses over a hierarchical structure over multiple chained calls', function() { myService.traverseTheStuff() .then(function(theAggregateResult) { // ...is never fulfilled }); $httpBackend.flush(); }); Other single-call tests will register the callback passed to .then() and execute it as soon as I call .flush(). The code under test looks something like this.

Private method Unit testing with Jasmine

天涯浪子 提交于 2019-12-31 12:26:02
问题 I was coding test cases for an angular application using jasmine. But many internal methods are declared as private in the services. Example: App.service('productDisplay', function(){ var myPrivate = function(){ //do sth } this.doOfferCal = function(product, date){ //call myPrivate //do sth too return offer; } }); Using jasmine it straightforward to code test for "doOfferCal" but I want to write unit test for myPrivate too. How can I do it? Thanks in advance. 回答1: Is there a specific reason

Global `beforeEach` in jasmine?

被刻印的时光 ゝ 提交于 2019-12-31 10:57:11
问题 I'm using Jasmine to write tests. I have several test files, each file has a beforeEach , but they are exactly the same. How do I provide a global beforeEach for them? 回答1: You can put it in your spec_helper.js file and it should work fine. 回答2: x1a4's answer confused me. This may be more clear: When you declare a beforeEach function outside all describe blocks, it will trigger before each test (so before each it ). It does not matter if you declare the beforeEach before or after your

Redirect calls to console.log() to standard output in Jasmine tests

蓝咒 提交于 2019-12-31 10:06:43
问题 I'm using Jasmine via the jasmine-maven-plugin, and I would like to see console.log() messages in the Maven build output. Is there a way to achieve this? If console.log() cannot be redirected, is there any other way to log from my tests so that they show up on the Maven build output? I'm running these tests on Jenkins in a headless fashion, and would like a means to get some debug output from the tests. 回答1: Try console.info('foo') From the test javascripts. 回答2: You can use: jasmine.log("I

Test for rejected promise with Jasmine

空扰寡人 提交于 2019-12-31 05:11:10
问题 In my Angular2 app which uses AngularFire2, I have an AuthService which tries to authenticate anonymously with Firebase. I am trying to write a test that expects AngularFireAuth 's signInAnonymously to return a rejected promise; for authState to be null and an error to be thrown. I an new to Jasmine and testing in general but I think I may need to be using asynchronous tests but I'm getting quite stuck. Here is a simplified AuthService : import { Injectable } from '@angular/core'; import {

Using Karma-runner with AngularJS, Jasmine, CoffeScript

巧了我就是萌 提交于 2019-12-31 01:56:15
问题 My app besides jRuby/Rails uses AngularJS , CoffeScript . I'd like to test my javascript with Jasmine and run it with Karma (aka Testacular ), but I get an error stating that my Angular module is nowhere defined . What I've got: installed Node.js and Karma , generated a config file: // base path, that will be used to resolve files and exclude basePath = '../'; // list of files / patterns to load in the browser files = [ JASMINE, JASMINE_ADAPTER, 'vendor/assets/javascripts/angular.js', 'vendor

Failing unit test of factory with dependency in AngularJS using Jasmine & Karma

十年热恋 提交于 2019-12-31 00:56:09
问题 I am using Jasmine to test an AngularJS factory. I am having difficulty testing a factory that has a dependency. I have included the code for the factory I am testing and the test code. The problem is that I am getting errors and the test is failing. This is the error I am seeing: Chrome 33.0.1750 (Mac OS X 10.8.5) Testing my Test Service can get an instance of my factory FAILED Error: [$injector:unpr] http://errors.angularjs.org/1.2.8/$injector/unpr?p0=TestThisServiceProvider%20%3C-

void method testing javascript

感情迁移 提交于 2019-12-30 22:53:56
问题 I have a method written in javascript and I am using Jasmine to test the method. The method is a void type which is invoking another method . I have to test if the method is invoking the other method, the present method is returning void. what should I write in the expect clause to compare it. sendMessage=function(data){ if(data!=null) { postMessage(data); } } Jasmine code : describe('unit test void method', function(){ it("sendMessage method should invoke the postMessage", function () {

Logging from grunt-contrib-jasmine

只谈情不闲聊 提交于 2019-12-30 16:25:10
问题 I'm using grunt-contrib-jasmine to run my javascript specs. How do I write debug output to the console when running specs i.e. how do I get console.log("something"); to show output in the console? I do find that I can get output by running: $ grunt jasmine --verbose But this prints a lot of information that I'm not interested in. How can I just see the output from console.log ? 回答1: Use console.info instead of console.log 回答2: Not a solution but a work around (sort of). Put in a expect(

What line is causing this Protractor error?

一个人想着一个人 提交于 2019-12-30 09:41:48
问题 Is there a way for Protractor to show in the console log what line the error occurred on? I just get this type of message: Message: Failed: Cannot call method 'click' of undefined Stack: Error: Failed: Cannot call method 'click' of undefined at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:104:16 at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15 at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/usr