w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
How to set jasmine for karma e2e for testing angular app?
Angular e2e tests with Karma don't and can't use the JASMINE adapter. Instead you have the ANGULAR_SCENARIO_ADAPTER which has a similar feel to writing Jasmine tests. All commands in the adapter's API are asynchronous anyway. For example element('#nav-items').count() doesn't return a number, it returns a Future object. Future objects are placed in a queue and executed asynchronously as the runner progresses. To quote the API docs: expect(future).{matcher}: [...] All API statements return a future object, which get a value assigned after they are executed. If you need to run your own asynchronous test code, you can extend the adapter's DSL, this is easier than it might sound. The idea is that you return your own Future which can be evaluated by a matcher such as toBe(). There ar

Categories : Testing

can't run e2e tests with karma (for angular)
setting up karma for e2e testing you will also need to comment out JASMINE AND JASMINE_ADAPTER inside files in the karma.conf.js and add frameworks = "jasmine" underneath this. Hope this helps

Categories : Testing

Mocking Angular module dependencies in Jasmine unit tests
Here's what I figured out: I wasn't loading any 'angular-table' modules in my karma.conf.js file, hence the error. This was intentional at first as I wanted to test the 'events' module without the actual table module. I was able to easily mock the 'angular-table' module by creating a new file in my test folder called 'mocks/angular-table.js' and added the following code: /mocks/angular-table.js 'use-strict'; angular.module('angular-table', []); I added this file to my karma.conf.js file, along with the real 'events' module I wanted to test: karma.conf.js ... files = [ JASMINE, JASMINE_ADAPTER, 'scripts/libs/angular.js', 'scripts/libs/angular-mocks.js', 'scripts/events.js', // this is the real module. 'scripts/mocks/*.js', //loads all custom mocks. 'scri

Categories : Unit Testing

Including angular-scenario.js breaks my Rails Jasmine tests, as in they don't run
Jasmine and angular-scenario.js (e2e runner) are two different things and they should be run separately. Angular e2e test framework uses syntax which is very similar to jasmine. Probably when you include it along with jasmine it overrides some jasmine's methods like describe, it and beforeEach.

Categories : Angularjs

Need proper reporter for karma jasmine
Fixed by installing the karma-spec-reporter npm install karma-spec-reporter --save-dev and adding this my karma.config.js reporters: ['spec'], According to karma documentation By default, Karma loads all NPM modules that are siblings to it and their name matches karma-*. but some users have had to add the following to their config plugins: ['karma-spec-reporter']

Categories : Javascript

Grunt-Karma: Use Node.js fs-framework in Jasmine Testfile
I think you're missing the point of unit testing here, because it seems to me that you're copying application logic into your test suite. This voids the point of a unit test because what it is supposed to do is run your existing functions through a test suite, not to test that fs can load an XML file. In your scenario if your XML handling code was changed (and introduced a bug) in the source file it would still pass the unit test. Think of unit testing as a way to run your function through lots of sample data to make sure it doesn't break. Set up your file reader to accept input and then simply in the Jasmine test: describe('My XML reader', function() { beforeEach(function() { this.xmlreader = new XMLReader(); }); it('can load some xml', function() { var xmldu

Categories : Node Js

Errors with Karma and Jasmine caused by cross-domain AJAX
If it really is a CORS issue, you can disable the cross-domain by starting karma like this: karma start --browsers chrome_without_security Chrome has the ability to be started with the security disabled open -a Google Chrome --args --disable-web-security And the Karma team just takes advantage of it.

Categories : Javascript

jasmine-node says "0 tests" when there *are* tests
Don't you miss describe? describe("A suite", function() { it("contains spec with an expectation", function() { expect(true).toBe(true); }); }); Running: c:Temp>jasmine-node --verbose my.Spec.js A suite contains spec with an expectation Finished in 0.007 seconds 1 test, 1 assertion, 0 failures, 0 skipped everything works fine.

Categories : Javascript

Running tests with Karma on IE8
Chances are you're running jQuery 2.x. jQuery comes in two branches today: 1.x - This is the older branch which runs on old and new browsers from IE6 up. 2.x - This is the newer rewrite which is smaller and faster but only runs on newer browsers, they support IE9+. see this release note. jQuery 2.0 has arrived! As promised, this version leaves behind the older Internet Explorer 6, 7, and 8 browsers. In return it is smaller, faster, and can be used in JavaScript environments where the code needed for old-IE compatibility often causes problems of its own. Luckily, the latest jQuery 2.x is (at least at the moment) fully interchangeable with the latest jQuery 1.x so you supposedly can make the switch seamlessly. And just for the record it's attachEvent in IE8 ;)

Categories : Jquery

Angular JS/Karma Unit Testing with Angular UI-Router
At first glance I would say it looks like the $stateProvider is telling you you need to put an empty state in there. Add this to the list of states. state( '', { ... } )

Categories : Unit Testing

Output tests to browser with Karma
Accroding to Documention, even not very perfect: If 'singleRun' is false, it will set the ci-mode on, so, make it true, and you will see some failed red status on the top bars of browers.

Categories : Javascript

Run a function whenever Karma tests fail
Typically this would be done by the Continuous Integration server, for instance Jenkins. If you don't use it, I would recommend so. If you really want to implement this in Karma, you can write a custom reporter, there is a method onSpecComplete.

Categories : Api

angular-mock.js conflicts with htmlunit? How to test angular application using angular-mock.js in maven-jasmine
In the CHROME browser version the error occurs when angular tries to load JQLite a api-compatible subset of the jQuery library that allows angular to manipulate the DOM. I was able to fix the issue by downloading uncompressed versions of jQuery (v1.10.2), angular (v1.0.7), and angular-mocks (v1.0.7). I added the following to the configuration in the jasmine-maven-plugin. <preloadSources> <preloadSource>${angular-test-deps}/jQuery.js</preloadSource> <preloadSource>${angular-test-deps}/angular.js</preloadSource> <preloadSource>${angular-test-deps}/angular-mocks.js</preloadSource> </preloadSources> The angular documentation states that "Real jQuery always takes precedence over jqLite, provided it was loaded before DOMContentLoaded eve

Categories : Unit Testing

AngularJS + Require + Karma - having trouble getting tests to run
I don't think you want to bootstrap the application when you perform the tests. Have you tried to refactor that module to another file? For instance the file equivalent to your test-main.js for when you run your application. What I mean is that the module: require(['angular', 'helper'], function(angular, helper) { angular.element(document).ready(function() { /* MANUALLY LOAD TO WAIT FOR APP */ angular.bootstrap(document, ['mcc']); --> This line causes the error /* NAVIGATE TO TOP OF PAGE FOR MOBILE DEVICES */ window.scrollTo(0, 1); }); probably doesn't need to be loaded by Karma at all.

Categories : Angularjs

Karma runner console - output only failed tests
Looking at http://karma-runner.github.io/0.10/config/configuration-file.html Have you tried setting the config to use an empty reporters array? Karma v0.10 defaults to a reporters config of ['progress'], which is likely causing your verbose output. You might like the 'dots' reporter. You can try it on the CLI using karma start yourconfig.js --reporters dots

Categories : Javascript

AngularJS end-to-end tests using Karma with a static file instead of server
Okay, I got my end result: automated end-to-end testing on Semaphore. The trick was to create a separate test-index.html that uses a test version of my app. It has <html ng-app="TestMyApp"> instead of <html ng-app="MyApp">. It also includes the following extra JavaScript that my actual index.html does not: <script src="http://code.angularjs.org/1.0.7/angular-mocks.js" type="text/javascript"></script> <script src="spec/e2e/test_api_app.js" type="text/javascript"></script> My test_api_app.js is actually compiled from CoffeeScript by the karma-coffee-preprocessor, but here is the CoffeeScript source: angular.module('TestMyApp', ['MyApp', 'ngMockE2E']).run ($httpBackend) -> $httpBackend.when('GET', 'http://some-api-my-app-uses/images').respond s

Categories : Javascript

How would you run jasmine tests on a CI environment *without nodejs*
You can make your test automatically spawn a browser with the page that runs your unit test. The tricky part tough is to get the result back to the main test runner. The solution that I have found for that is to use a custom jasmine reporter (you just need to implement the same function has to other reporter) and when a spec has finished to run you do an AJAX call to write that result in a file. The main runner just needs to wait until something is written in that file to see the results. Once the test are finish, just don't forget to kill the browser, otherwise your CI server will be flooded by window.

Categories : Jenkins

What should I write unit tests for in Jasmine?
The majority of them deal with the html code such as changing a tab, showing a notification, disabling/enabling controls. What you want to verify for that is if the resulting behavior is correct (ex.: content changed). This is typically done with integration test and Jasmine isn't the best tools for integration testing. Tools such as Selenium will do a better job that kind of test. Just don't fall in trap of starting to test if a specific function is called to verify if the functionality is still working properly. The internal of that functionality can change and call other function and that doesn't mean it's now broken. So that's why it's better to do it at an higher level (integration testing). The problem I am having is what should I be writing tests for, and how many Norma

Categories : Javascript

How do I make Karma's auto-watch feature pause before running tests?
From the karma documentation, it seems there is an "exclude" option to remove some file pattern. If you modify your option to have a different name for backup and ignore Vim backup format, it should work properly. But it will change your workflow somehow, you'll probably have to ignore the backup in your .gitignore as well. Just a comment aside, I feel like with vim persistent undo (version >7.3), it seems that the backup file is a bit redundant. So maybe use, set nobackup set undodir=~/.vim/undodir if (v:version >= 703) set undofile set undolevels=1000 "maximum number of changes that can be undone set undoreload=10000 "maximum number lines to save for undo on a buffer reload endif

Categories : Javascript

How can I load HTML fixtures for Javascript unit tests in Karma with Mocha?
I have a demo that uses html fixtures with jasmine here and the demo description contains links to a screencast and github repo for running with Karma. See this link.

Categories : Javascript

AngularJS : e2e tests with Karma Scenario Test Runner using cached source?
In Chrome developer tools settings, check "Disable cache (while DevTools is open)". Obviously, this is a much more general issue than Angular's e2e test runner, but I decided to leave it here for now, in case somebody else has the same question.

Categories : Testing

How to ensure DRY code in Jasmine Unit tests?
It`s a bad thing to rely to test order. To share things between tests you can have a way to set state of an object. Assume the pseudo code below: var popover = getPopover({state:'init'}); //checking init state ... //other test starting var popover = getPopover({state:'manipulated'}); //checking the state So the main idea is to be able to init your object at the state you need. Note, that if it's not much code to perform initialization and you are not going to need to reuse it much, you can hardcode the state setup for every test. Sure, it's not dry, but you benefit from tests that can be read, without references to other methods. Sometime it's a good thing, but it depends. Also, you can use beforeEach and afterEach for setup and teardown before and after every test( it's a describe lev

Categories : Javascript

AngularJs Unit Tests with Jasmine and RequireJs
I had loads of issues getting angular, mocking and require to play nice with jasmine. In the end the answer was obvious you need to boot jasmine up and ensure it's fed your specs. This is a cut down version of what I did, I hope it helps to get you on the right track. /* this would be 'main'*/ require.config({ paths: { 'jasmine-boot': 'lib/jasmine/boot', 'jashtml': 'lib/jasmine/jasmine-html', 'jasmine': 'lib/jasmine/jasmine', 'angular': 'lib/angular', 'angular-mocks': 'lib/angular-mocks', 'app': 'src/app', 'test': 'spec/first.spec', }, shim: { 'jashtml': { deps: ['jasmine'] }, 'jasmine-boot': { deps: ['jasmine', 'jashtml'] },

Categories : Angularjs

Mocking dates in AngularJS / Jasmine tests
A straightforward solution would be to create an Angular Dates service that provides Date objects for you - it might even just have a single method - Dates.now() - that just sends back the current date by returning new Date(). You then use this service whenever something needs to get the current date. This then allows you to inject a different Dates service when unit testing, for example one that always returns a specific date of your choice when called, rather than the current time.

Categories : Unit Testing

Debugging jasmine tests with resharper and phantom js
To debug in the browser, add the code below to your js test file. jasmine.getEnv().currentRunner_.finishCallback = function () {}; Resharper won't be notified that the test has finished so we can set debug breakpoints in the opened browser (I use chrome) and F5 the page. Stop the tests in resharper testrunner window when you're done. Edit: Since Jasmine 2.0 you need to use: ReSharperReporter.prototype.jasmineDone = function () { };

Categories : Unit Testing

Why do these resharper Jasmine tests run in browser but not in phantomjs
Eureka... the problem was an ID-ten-T otherwise known as PEBCAK I hadn't thought about or investigated how R# was actually going to run the tests. And so had set the reference paths in the Spec.js relative to my specrunner.html R# actually injects the Spec file into an html page as an inline script so my relative paths were all wrong. I simply set the reference paths as absolute from the project root and all was fine. // The Jasmine Test Framework /// <reference path="/Scripts/jquery-1.10.1.js"/> /// <reference path="/Scripts/tests/lib/jasmine-1.3.1/jasmine.js"/> /// <reference path="/Scripts/tests/lib/jasmine-1.3.1/jasmine-html.js"/> /// <reference path="/Scripts/tests/lib/jasmine-jquery.js"/> /// <reference path="/Scripts/tests/lib/mock-ajax.js"/> // Cl

Categories : Javascript

Karma e2e test fails with typerror
Your syntax on the test is wrong It needs to be: expect(repeater('div.grid-item').count()).toEqual(1); Read up on the e2e domain specific language... It is not angular or jquery, it's a little mysterious, but powerful. To better debug e2e tests, use a test runner instead of using Karma. This is the file called runner.html included with the angular-seed starter app: <!doctype html> <html lang="en"> <head> <title>End2end Test Runner</title> <script src="../lib/angular/angular-scenario.js" ng-autotest></script> <script src="scenarios.js"></script> </head> <body> </body> </html> Just navigate to runner.html in your browser and it starts running your tests in front of you, just refresh to

Categories : Angularjs

Best practice for binding event handlers in Jasmine tests that use fixtures?
I have an example of DOM manipulation with Jasmine using jasmine-jquery here. You will also see a link in the description therein to a github repo you can clone to provide more insight into how SpecRunner.html orders dependencies. Basically I have my html fixtures with their onclick events followed by a jquery click() all in my jasmine beforeEach(). I then have my test expectations also check the DOM for validation. This may be along the lines of your #2 workaround above.

Categories : Javascript

Testing angular with karma: how to set scope
Short story: change the compiled element to <div hy-plugin-window content="content"></div> and I think it should work. The directive has an ISOLATE scope, which means it does not prototypically inherit from the "regular" scope. In your test, you are defining content on the regular scope, but the directive itself is encapsulated - it has isolated scope and therefore does not see the content property defined on the regular scope. You need to communicate that through the explicit interface of the component, which is content attribute.

Categories : Angularjs

Angular e2e / Karma - Before Suite block?
If you don't mind the block being run for every test in your suite you could nest your tests and have a beforeEach at the highest level, e.g., describe("Entire Suite", function() { beforeEach(function(){ // Executed for every it in the entire suite }); it('Test', function() { // Only the first beforeEach will be called prior to this test. }); describe("Subset Suite", function(){ beforeEach(function(){ // Executed for every it in this subset suite }); it('Subtest', function() { // Both beforeEach blocks will have been called prior to this test. }); }); However, the main beforeEach will execute before every it block in the entire suite. If you want the code to be executed only once then this isn't the solution for you.

Categories : Angularjs

Can't include wijmo-angular in GruntJS (with Karma Runner)
It works when using the latest version of that problematic script: http://cdn.wijmo.com/interop/angular.wijmo.3.20132.9.js

Categories : Angularjs

Testing angular factories with jasmine
The problem is In your production code var dataLoadedPromise = $http.get('myData.xml', {transformResponse: transformResponse}); you expect the return from the server is XML data not json, so when you mock the HTTP, you should use XML instead of Json. Here is the working code: describe("controller: MyController", function () { beforeEach(function () { module("myApp"); }); var dataFactory; beforeEach(inject(function ($injector, $controller, $rootScope, $location, $httpBackend) { this.$location = $location; this.$httpBackend = $httpBackend; this.scope = $rootScope.$new(); dataFactory = $injector.get('dataFactory'); this.$httpBackend.expectGET('myData.xml').respond( "<?xml version="1.0" encoding="UTF-8" ?

Categories : Unit Testing

Using Jasmine with Angular JS input validation
The jasmine error indicates that you are trying to access a null object. This appears to occur when you are accessing the len instead of the len - 1 index of the array. Try changing the expectation to: expect($("input[ng-model='d.billingNumber']")[len - 1].classList.contains("ng-invalid")).toEqual(true);

Categories : Javascript

Calling `sleep` or `pause` in karma scenario for angular app breaks framework
I would suggest using Protractor for your Angular E2E tests. This has awareness of angular and returns promises. You could do something like this then: ptor.get('http://localhost/#/my-route').then(function () { // Do something }); You can also use ptor.wait like this: var timeout = 10000; ptor.wait(function () { return {some condition} }, timeout); Which will wait for a condition to be true before moving on. Also you can use ptor.waitForAngular() which will wait for angular to resolve any promises and http requests.

Categories : Javascript

Faking a Angular Factory in a directive in jasmine
You can use the $provide to inject your controller dependencies. Here's my beforeEach for example: describe('MyCtrl', function() { var $controller, $scope, $httpBackend, windowMock, registerHtmlServiceMock, mixPanelServiceMock, toastMock; beforeEach(function() { windowMock = { navigator: {} }; registerHtmlServiceMock = {}; mixPanelServiceMock = jasmine.createSpyObj('mixpanel', ['track']); toastMock = jasmine.createSpyObj('toast', ['error']); module('myModule'); module(function($provide) { $provide.value('$window', windowMock); $provide.value('RegisterHtmlService', registerHtmlServiceMock); $provide.value('MixPanelService', mixPanelServiceMock);

Categories : Unit Testing

How to test Angular Factory Objects using Jasmine
You can mock the Http GET request and test the service like this describe("getCustomers", function (service) { beforeEach(module('app')); var service, httpBackend; beforeEach(function () { angular.mock.inject(function ($injector) { httpBackend = $injector.get('$httpBackend'); service = $injector.get('service'); }) }); describe('getCustomers', function () { it("should return a list of customers", inject(function () { httpBackend.expectGET('/Home/Customers').respond(['david', 'James', 'Sam']); service.getCustomers(function (result) { expect(result).toEqual(["david", "James", "Sam"]); }); httpBackend.flush(); })) }) }); Working Demo

Categories : Javascript

Using angular.mock.inject in karma gives "TypeError: Cannot read property '$injector' of null"
I commonly run into this error when the issue is simply an un-closed ) or } Outside of that, an approach to debug the issue might be to simplify until the problem goes away. That is, start removing large portions of code, a bit at a time, until you've "binary-searched" for the issue.

Categories : Javascript

Angular Test tutorials on Jasmine website not working
You're using old karma's configuration style. I see two options 1) you have quite old karma version, 2) you are trying to run new karma on the old configuration style. You should try to upgrade karma to the newest version and migrate your configuration to the new style, see: http://karma-runner.github.io/0.10/config/configuration-file.html

Categories : Unit Testing

Writing Unit Test Case in Angular JS using Jasmine
You would write something along these lines: describe('MyApp controllers', function() { describe('MainCtrl', function(){ it('should populate the query', function() { var scope = {}, ctrl = new MainCtrl(scope); expect(scope.mainpage).toEqual(someMainPageMock); }); }); }); This is well documented, see the AngularJS tutorial for a quick reference, it's also suggested to read the Jasmine docs (!). You'd also want to spy on the query() method, see here on how.

Categories : Angularjs

Configuring Angular service provider in Jasmine test
By the time you call the config function your module is in the run phase. At that point you can no longer inject a provider. Try moving the function that has someServiceProvider injected into it. beforeEach(module('myModule', function(someProvider) { someProvider.configure(1); })); it('should work now', inject(function(some) { expect(some.func()).toBeAvailable(); }));

Categories : Unit Testing



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.