jasmine

Angular-cli test coverage all files

若如初见. 提交于 2019-12-20 18:09:10
问题 I am running the following command to unit test and generate code code coverage report. ng test --code-coverage It is writing code coverage report in coverage folder. I need to see the coverage of the whole project and not just the file for which there are tests. karma.conf.js module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine', 'angular-cli'], plugins: [ require('karma-jasmine'), require('karma-jasmine-html-reporter'), require('karma-chrome-launcher'),

Conditionally ignore individual tests with Karma / Jasmine

≯℡__Kan透↙ 提交于 2019-12-20 17:25:04
问题 I have some tests that fail in PhantomJS but not other browsers. I'd like these tests to be ignored when run with PhantomJS in my watch task (so new browser windows don't take focus and perf is a bit faster), but in my standard test task and my CI pipeline, I want all the tests to run in Chrome, Firefox, etc... I've considered a file-naming convention like foo.spec.dont-use-phantom.js and excluding those in my Karma config, but this means that I will have to separate out the individual tests

Generate jasmine report using Karma Runner

妖精的绣舞 提交于 2019-12-20 16:50:11
问题 I want to obtain a report of all successful jasmine specs runned with karma, something like you obtain when using jasmine alone. Is there anyway to achieve this? 回答1: Try this quick plugin I wrote: https://github.com/dtabuenc/karma-html-reporter 回答2: tl;dr Yes, but it's non-trivial, and even more so if you want --auto-watch . So, basically, no :-( Blame it on lib/reporters/Progress.js, which swallows successful test results and spits out a summary line for each browser. If you're determined,

Angular resource testing: $httpBackend.flush() cause Unexpected request

旧城冷巷雨未停 提交于 2019-12-20 14:12:37
问题 I want to test angularjs resource. 'use strict'; /** * AddressService provides functionality to use address resource in easy way. * * This is an example usage of method: * * `get`: * var a = AddressService.get({id: '1'}, function (data) { // Work here with your resource } ); * */ App.factory('AddressService', function ($resource, $rootScope) { var url = [ $rootScope.GLOBALS.API_PATH, $rootScope.GLOBALS.API_VERSION, 'models/address/:id' ].join('/'), actions = { 'get': { method: 'GET', params:

Javascript.confirm() and Angularjs Karma e2e test

谁说胖子不能爱 提交于 2019-12-20 12:23:19
问题 I have an Angularjs application that uses simple javascript confirm before executing some actions. Controller: function TokenController($scope) { $scope.token = 'sampleToken'; $scope.newToken = function() { if (confirm("Are you sure you want to change the token?") == true) { $scope.token = 'modifiedToken'; } }; } View: <div id="tokenDiv"> Token:{{token}} <button ng-click="newToken()">New Token</button> </div> Now I want to have an end to end test to check the token is being replaced correctly

jasmine 2.0 test with a custom matcher fails: undefined is not a function

淺唱寂寞╮ 提交于 2019-12-20 10:25:09
问题 I have this function in my source file: function gimmeANumber(){ var x = 4; return x; } And a spec borrowed from this tutorial describe('Hello world', function() { beforeEach(function() { this.addMatchers({ toBeDivisibleByTwo: function() { return (this.actual % 2) === 0; } }); }); it('is divisible by 2', function() { expect(gimmeANumber()).toBeDivisibleByTwo(); }); }); This is the error: TypeError: undefined is not a function at Object. (file:///home/n/foo/jasmine/jasmine-2.0.0/dist/spec

How to Load a File for Testing with Jasmine Node?

好久不见. 提交于 2019-12-20 10:24:45
问题 I have a simple JavaScript file, color.js , and a matching spec file, colorSpec.js . color.js: function Color() { } colorSpec.js: require('./color.js'); describe("color", function() { it("should work", function() { new Color(255, 255, 255); }); }); When I run jasmine-node colorSpec.js , I get the following exception: ReferenceError: Color is not defined How can I get Jasmine to load my color.js file before running colorSpec.js ? 回答1: you could load your color.js in the colorSpec.js with a

Some of your tests did a full page reload - error when running Jasmine tests

心已入冬 提交于 2019-12-20 10:21:50
问题 I'm running into an issue where when I run my tests on Jasmine, I get this error below. The problem is, it seems to happen when I try to execute a certain amount of tests. It doesn't seem to be tied to a particular test, as if I comment out some, the tests pass. If I uncomment some tests, the error appears. If I comment out ones that were uncommented before, they all pass again. (ie if I have red, green, blue and orange test and it fails, I comment out orange and blue it passes, then I

Getting “$digest already in progress” in async test with Jasmine 2.0

戏子无情 提交于 2019-12-20 10:19:40
问题 I know that calling $digest or $apply manually during a digest cycle will cause a "$digest already in progress" error but I have no idea why I am getting it here. This is a unit test for a service that wraps $http , the service is simple enough, it just prevents making duplicate calls to the server while ensuring that code that attempts to do the calls still gets the data it expected. angular.module('services') .factory('httpService', ['$http', function($http) { var pendingCalls = {}; var

AngularJS Protractor - Finding an Element on a Page Using Ng-Click Binding

别来无恙 提交于 2019-12-20 10:19:23
问题 I have a button on a page that looks like: <button ng-click="myFunction()" ng-show="flag"> Submit </button> The element has no ID. Is there a way to find this element using the function bound to Ng-Click? Or do I have to assign an ID to this element to locate it using Jasmine / Protractor? 回答1: Just tested this and it works: element(by.css('[ng-click="myFunction()"]')) 回答2: I went through the Protractor API and didn't find anything related to finding an element through ng-click . I did find