JavaScript for Li...
Follow
Find tag "Karma"
401.6K views | +96 today
JavaScript for Line of Business Applications
Keeping track of current JavaScript Frameworks that help design your clientside Business Logic Layers.
Curated by Jan Hesse
Beam to my Inbox:
Your new post is loading...
Your new post is loading...
Scoop.it!

Testing ReactJS Components with Karma and Webpack

Testing ReactJS Components with Karma and Webpack | JavaScript for Line of Business Applications | Scoop.it

I switched over to Karma to test my components, and spent my time building my test assets and loading them up to Karma, but that ended up being kind of slow because I never cached the builds and ran a clean webpack build for each bundle. Ugh. Facebook went on to release Jest and I switched over. I thought it was great, but I quickly ran into some issues...

more...
No comment yet.
Scoop.it!

An Introduction To Unit Testing In AngularJS Applications

An Introduction To Unit Testing In AngularJS Applications | JavaScript for Line of Business Applications | Scoop.it

One of the reasons for AngularJS’ success is its outstanding ability to be tested. It’s strongly supported by Karma (the spectacular test runner written by Vojta Jína) and its multiple plugins. Karma, combined with its fellows MochaChai and Sinon, offers a complete toolset to produce quality code that is easy to maintain, bug-free and well documented.

Tests must define the code’s API. This is the one principle that will guide us through this journey. An AngularJS application is, by definition, composed of modules. The elementary bricks are materialized by different concepts related to the granularity at which you look at them. At the application level, these bricks are AngularJS’ modules. 

more...
No comment yet.
Scoop.it!

Unit Testing w/ AngularJS

Unit testing is all about isolation and dependency injection makes isolation a breeze. Seasoned Java developers have known this for years. The Spring framework, ubiquitous in Java backends today, introduced dependency injection (or at least popularized it) and brought a great number of benefits in terms of decoupling, modularity, flexibility and testability. Simply put, dependency injection lets you swap out real implementations for mock ones and it damn near forces you to decouple every component.

more...
No comment yet.
Scoop.it!

Testing & Tooling in EmberJS

Testing & Tooling in EmberJS | JavaScript for Line of Business Applications | Scoop.it

One of my favorite parts of Ember is how easy it is to test. The framework comes bundled with a system testing framework, and its object model makes unit testing a breeze. Combine all that with a great test runner that has CI integration, and you have a really awesome testing ecosystem for your new app.

This framework allows you to make high-level assertions regarding your applications’ state, mostly by querying and interacting with the DOM through JQuery in a black box fashion. Since the tests are pure JavaScript however, we also get direct access to our running application if needed for testing.

The framework comes bundles with a few simple helpers to do common operations such as clicking a button, filling in a text field, or querying for the presence of a certain DOM element. A typical system test using ember-testing might look like this...

more...
No comment yet.
Scoop.it!

Ember.js Testing

When I started playing around with Ember.js almost a year ago, the testability story left something to be desired. You could unit test an object without any trouble, but a unit test is only one way to get feedback when you’re building a software product. In addition to unit tests, I wanted a way to verify the integration of multiple components. So like most people testing rich JavaScript applications, I reached for the mother of all testing tools, Selenium.

Now before I bash it, without a proper introduction, it’s worth mentioning that Selenium is a great way to verify your entire web application works with a full production-like database and all your production dependencies, etc. And from a QA perspective, this tool can be a great resource for teams who need end-to-end UI acceptance tests.

But over time, a seemingly small test suite built on Selenium can begin to drag the velocity of your team to a snails pace. One easy way to reduce this pain is to avoid building a large application in the first place. If you build a handful of smaller web applications instead, it might help keep you afloat for a little longer because no individual build will crush the team, as you grow.

But even on a small project, the real problem with Selenium is that it’s not part of the test driven development process. When I’m doing red/ green/ refactor I don’t have time for slow feedback in any form. I needed a way to write both unit and integration tests that would provide quick feedback to help me shape the software I was writing in a more iterative way. If you are using a version of Ember.js >= RC3, you’re in luck because writing a unit or integration test is a walk in the part.

Ember.js Testing
more...
No comment yet.
Scoop.it!

Code Coverage of Mocha Tests using Istanbul and Karma

Code Coverage of Mocha Tests using Istanbul and Karma | JavaScript for Line of Business Applications | Scoop.it

Many JavaScript projects are using Mocha to run the unit tests. Combining Mocha with Istanbul andKarma, it is easy to track the code coverage of the application code when running the tests.

While Mocha has a built-in support for running the tests from the command-line via Node.js, in some cases you still want to verify your code with the real web browsers. The easiest way to do that with by using Karma to automatically launch the browsers, control them, and execute the tests. 

more...
No comment yet.
Scoop.it!

Walkthrough: Killing Bugs in AngularJS with Karma & Jasmine

Walkthrough: Killing Bugs in AngularJS with Karma & Jasmine | JavaScript for Line of Business Applications | Scoop.it
Follow along in this two part series as we walk through the steps to test for bugs in AngularJS.

First, we will write unit tests that reflect the intended behavior and then fix the bug so these tests pass. The goal is to improve code maintainability and reduce regression bugs.Download or clone the repo to follow along – each step has a corresponding branch to checkout.

We are going to focus on the play/pause functionality of the player. By right-clicking on the video element, we can see that the video will play and pause.

We will write tests for both the controller and the directive for this button in order to make sure our tests are small, consistent and maintainable.

more...
No comment yet.
Scoop.it!

Unit testing an AngularJS directive

Unit testing an AngularJS directive | JavaScript for Line of Business Applications | Scoop.it

In this article, i’ll detail the process to unit test the stepper directive we’ve created in the last week custom component creation article. Next week, i’ll cover how to distribute your component via GitHub and Bower.

Unit testing is the art of testing individually every smallest part of your code, which are the foundations of your apps sanity. Once correctly tested, these parts assembled together will also play nicely, as their behaviour has already been validated independently.

Unit testing helps you prevent regressions, increase quality, maintenability, and trust in your codebase, thus better team collaboration, easier refactoring… and WIN :)

Another usage is, when you get a new bug report, you add the revelant test that demo the bug, fix it in your code so the test will pass, then keep it there as a proof of reliability.

more...
No comment yet.
Scoop.it!

Code Coverage of Jasmine Tests using Istanbul and Karma

Code Coverage of Jasmine Tests using Istanbul and Karma | JavaScript for Line of Business Applications | Scoop.it

For modern web application development, having dozens of unit tests is not enough anymore. The actual code coverage of those tests would reveal if the application is thoroughly stressed or not. For tests written using the famous Jasmine test library, an easy way to have the coverage report is viaIstanbul and Karma.

Behind the scene, Karma is using Istanbul, a comprehensive JavaScript code coverage tool (read also my previous blog post on JavaScript Code Coverage with Istanbul). Istanbul parses the source file, in this example sqrt.js, using Esprima and then adds some extra instrumentation which will be used to gather the execution statistics.

more...
No comment yet.
Scoop.it!

BrowserStig = Developer Friendly Browser Automation

BrowserStig = Developer Friendly Browser Automation | JavaScript for Line of Business Applications | Scoop.it

Although BrowserStig may be used for other automation purposes, it's main purpose is to be used for functional testing. As mentioned before, you can use browserstig.js standalone without the cli. This would allow you to import browserstig.js into any javascript testing framework. However, the stig cli is designed to help you start testing immediately with minimal setup.

If you have used the karma test runner, you will be familiar with the stig cli. Really, the stig cli just wraps the karma test runner. The supported test styles are 'mocha', 'jasmine' and 'qunit'. However, this documentation only covers testing with mocha.

more...
No comment yet.
Scoop.it!

Advanced Testing and Debugging in AngularJS

Advanced Testing and Debugging in AngularJS | JavaScript for Line of Business Applications | Scoop.it
Learn to test, debug and prepare the test code on your AngularJS application like a Pro using Jasmine unit testing and Protractor integration testing

AngularJS is becoming immensely popular and mainstream which means that there is a lot of AngularJS code out there that is being tested or is yet to be tested. And now that you're well on your way to test like a pro, thanks to the abundance of articles, tutorials, books and material out there on AngularJS testing & development, testing should be a mandatory process of your web development workflow.

Full-Spectrum testing with AngularJS & Karma taught us how to test certain areas of your AngularJS application, but how do we test efficiently? How do we debug a problem down the root cause? How do we skip tests, set breakpoints, and professionally mock-out our test components so that we can catch hidden bugs and unexpected scenarios? How far can and should we go with Unit & E2E testing? What else should we consider. Well lets take adeeper dive into testing in AngularJS and expand our minds by learning how to become a professional front-end tester.

Table of Contents:
* Presentation Slides + Video
* What to test and what not to test
* Preparing your test environment with Karma & Grunt
* Write tests as you go
* So when do you do your testing?
* Module & Inject Breakdown
* Powerful Mocking Strategies
* Sync' and Async' testing
* Skipping and Filtering tests
* Echoing data back to screen
* Using Breakpoints
* Writing Efficient Tests
* Testing older browsers
* Invest into preparing a CI environment
* Feedback Please!

more...
No comment yet.
Scoop.it!

Setting-up AngularJS, Angular Seed, Node.js and Karma

Setting-up AngularJS, Angular Seed, Node.js and Karma | JavaScript for Line of Business Applications | Scoop.it

I’ve used AngularJS for a few months, but I have no knowledge when it comes to testing AngularJS apps. I have a subscription to PluralSight.com and wanted to go through their online video training course for AngularJS. Specifically with this course I want to learn how to use Karma to do testing.

I’m usually extremely happy with PluralSight.com course, but in the beginning of this course I was somewhat disappointed. In Section 7 (“Angular Seed”) new technologies were introduced. The author introduced Angular-Seed, Node.js and Karma. I’ve worked with Node.js, but there are probably many people who have never used it. I believe the author took for granted that the student knew Node.js. For those who have never used Node.js this could be an obstacle.

Here are the high level step we will follow:

  1. Download and install Angular-Seed
  2. Download and install JetBrains WebStorm (Optional)
  3. Download and install Node.js
  4. Confirm Node.js is installed
  5. Run Karma Unit Tests – will fail because Karma is not installed
  6. Install Karma
  7. Run Karma Unit Tests again – Will fail because Chrome will not start
  8. Add System Variable to Windows
  9. Confirm System Variable Were Added
  10. Run Unit Tests again – should succeed
  11. Confirm that Units are being tracked by Karma
  12. Start Web Server by using Node.js
more...
No comment yet.
Scoop.it!

Testing Angular.js

Testing Angular.js | JavaScript for Line of Business Applications | Scoop.it

As an Angular.js developer, I want to test my code, so that I can feel reasonably good about it. This sounds like a "User Story" in Scrum but it's more of a developer quest. So in this blog we will look at ways to test our Angular.js code.

Let's see what we need -

We need to write unit tests for our

* Controllers

* Services

* Directives

* Filters

We need to write end-to-end tests so that we can be sure everything is working well together

more...
No comment yet.
Scoop.it!

Testing Angular with Karma

Testing Angular with Karma | JavaScript for Line of Business Applications | Scoop.it

The Angular team at Google provides two tools for testing Angular applications: Karma, a test runner for unit testing, and Protractor, a test framework for writing end-to-end (E2E) tests. In this article, I'm going to be focusing on writing unit tests against Angular applications using Karma. We'll cover some unit-testing basics, Karma details, as well as Angular-specific strategies for writing unit tests that help improve overall developer productivity instead of adding an extra development burden to your application.

more...
No comment yet.
Scoop.it!

AngularJS Unit Testing - For Real, Though

AngularJS Unit Testing - For Real, Though | JavaScript for Line of Business Applications | Scoop.it

This article is written for intermediate to advanced developers using AngularJS to build production applications, who would like to reduce some of the pain of testing. It is my hope that feeling secure in testing workflow will enable the reader to practice a TDD workflow and build a more solid app.

more...
No comment yet.
Scoop.it!

Test-Driven Development of Ember.js Applications

In this session, I will present a walkthrough of Ember.js core features. I will showcase a test-driven development of Ember.js application using Jasmine. I will also explain Ember.js' data bindings that allow for creation of views that update automatically in response to model changes. I will demo ease of Ember.js and Rails integration. Finally, I will utilize Ember.js components to create reusable UI elements.

Jan Hesse's insight:

Slides:

https://speakerdeck.com/antityping/test-driven-ember-dot-js

Code:

https://github.com/AntiTyping/EmberDo

more...
No comment yet.
Scoop.it!

Ember.js Testing

Ember.js Testing | JavaScript for Line of Business Applications | Scoop.it

Now that we can write JavaScript tests for our application, how do we execute them? Most developers start out using the browser directly, but because I wanted something I could execute headless from the command line in a CI environment with a rich ecosystem full of plugins, I looked to Karma.

What I liked about Karma is that it only wants to be your test runner. It doesn’t care what JavaScript test framework you use or what client side MVC framework you use. It’s simple to get started with and writing tests that execute against your production Ember.js application is just a few lines of configuration.

 

* Configure the Test Runner
* Unit Testing the Computed Property
* Add the Karma-Ember-Preprocessor and Configure It
* Integration Testing the Data-Bound Template
* Should I Write Unit or Integration Tests?
* Conclusion

more...
No comment yet.
Scoop.it!

Boilerplate web app using Backbone.js, ExpressJS, node.js, MongoDB

Boilerplate web app using Backbone.js, ExpressJS, node.js, MongoDB | JavaScript for Line of Business Applications | Scoop.it

A boilerplate project for a complete web application written using Backbone.js & Marionette, node.js & ExpressJS, MongoDB & Mongoose, Handlebars, Grunt.js, Bower, and Browserify!

I created a super basic single page application (SPA) that is a simple Contacts manager. While this app is pretty simple, there’s actually a lot that’s involved. My goal with this article is to cover the entire stack of the application including; back-end, data, front-end, tools and testing. The stack consists of the following core technologies:

* Back-end: node.js and ExpressJS
* Data Layer: MongoDB and Mongoose
* Tools: Grunt, Bower and Browserify
* Testing: Jasmine, Karma, and PhantomJS
* Front-end: Backbone.js and Marionette.js

 

I’ll go into detail on each of the above components comprising the “full” stack. Again, because its such a simple app, not a whole lot of time will be spent covering the bells and whistles of the user interface or how the app works because that’s fairly obvious (nor did I spend a whole lot of time on the actual implementation, as I didn’t want it to distract from the core of the app). Instead, I’ll go into detail covering every aspect of how the app was built and the workflow process using the various tools.

The end goal is to have a code base to act as a boilerplate starter for any new projects down the road. The code should be fully functional and complete, yet easily digestible. Ultimately, after you read this article and have a solid understand of everything under the hood, you should be able to simply clone the repo and start building your app!

more...
No comment yet.
Scoop.it!

Testing AngularJS directive templates with Jasmine and Karma

Testing AngularJS directive templates with Jasmine and Karma | JavaScript for Line of Business Applications | Scoop.it

In my day job, I work on appear.in, a video chat service built with AngularJS and WebRTC. Recently, our application has become more complex, and our HTML templates ended up having a lot of state in them. We could no longer just use unit testing to verify our application logic, we also needed to test the state in our templates.

For our unit testing, we landed on using Jasmine and Karma, and this has worked fairly well for us. So when we wanted to test our templates, we wanted to use the same tools.

more...
No comment yet.
Scoop.it!

How to Unit Test Controllers In AngularJS Without Setting Your Hair On Fire

How to Unit Test Controllers In AngularJS Without Setting Your Hair On Fire | JavaScript for Line of Business Applications | Scoop.it
Developers almost universally agree that unit tests are a VERY GOOD THING when working on a project. They help you feel like your code is airtight, ensure reliability in production, and let you refactor with confidence when there is a need to do so.

AngularJS code touts its high degree of testability, which is a reasonable claim. In much of the documentation end to end tests are provided with the examples. Like so many things with Angular, however, I was finding that although unit testing was simple, it was not easy. Examples were sparse and though the official documentation provided some snippets of examples, putting it all together in my “real-world” case was proving challenging. So here I’ve written a little bit about how I ended up getting that wonderful green light for a passing build to show up.

* Instant Karma

* Writing Tests With Jasmine

* $httpBackend Is Cool

* Conclusion

more...
No comment yet.
Scoop.it!

Unit testing with angularjs, grunt, karma, and travisci

Unit testing with angularjs, grunt, karma, and travisci | JavaScript for Line of Business Applications | Scoop.it

If you’ve done much reading about angularjs you’ve no doubt come across mention of karma, a test runner recommended especially for use with angularjs applications. The angular-seed project is a great way to get started with the basics of angular testing using karma, but for projects of any significant size you will soon hit the cieling in terms of organization complexity. What I want to share in this article is the approach I have taken using Grunt and the grunt-karma plugin to sustainably manage my projects’ client side unit tests and run them via TravisCI.

more...
No comment yet.
Scoop.it!

AngularJs Good Unit Test Structure For Controllers & How to test ajax code and Promises

AngularJs Good Unit Test Structure For Controllers & How to test ajax code and Promises | JavaScript for Line of Business Applications | Scoop.it

The poorly the structure is made for unit testing the more and more complected it will take to write a unit test for a simple functioning piece of code , and it will feel that your fighting your way against testing, instead it should feel more fun! So i’ll be showing a structure that worked for me very well when working with angular controllers Before going deep with the structure, i’ll be using

* Jasmine (unit testing)

* Jasmine spies (mocking)

* karma (because its awesome)

more...
No comment yet.
Scoop.it!

An AngularJS Test Pyramid

An AngularJS Test Pyramid | JavaScript for Line of Business Applications | Scoop.it

As a team with a strong taste for automated testing we focused from the beginning on how to test our Angular app. In this post we want to describe our different types of tests and how they form a Test Pyramid.

Level 4: Selenium Tests.
Level 3: E2E (Scenario) Tests.
Level 2: Directive Tests.
Level 1: Unit Tests.

For each kind of test, we will explain the following aspects:

* Purpose: What’s the idea behind this type of tests. When to use and what is being tested (the scope of the test). Principles how to write the test.
* Implementation: How does it look like in source code. Examples, technical issues.
* Our experience: Reflection about our specific experience. Some heuristic data.

more...
Ehab Roufail's curator insight, October 7, 2013 12:29 PM

Very similar approach to what we are adopting and have adopted recently.

Scoop.it!

How To Unit Test An Angular App.

How To Unit Test An Angular App. | JavaScript for Line of Business Applications | Scoop.it

AngularJS has a great testing story - it’s all based on Dependency Injection, the Karma test runner was written by one of its core developers Vojta Jina and it ships with a variety of mocks like the $httpBackend for unit testing requests to remote services.

What I haven’t been able to find much of are examples showing how to take advantage of these features when testing an application that does more than just expose objects connected via a rest api.

Today we’re going to build a simple Tic-Tac-Toe game writing unit tests along the way.

more...
No comment yet.
Scoop.it!

How to build a large Angular.js application

How to build a large Angular.js application | JavaScript for Line of Business Applications | Scoop.it

Angular.js is built from the ground up with testing in mind. In our opinion this makes Angular different from all other frameworks out there. It is the reason we chose it.

This testability is due to the feature set of Angular and the tooling available. Feature wise,dependency injection (DI), modulesdirectivesdata binding, and the internal event loop all work together to create a testable architecture.

Angular maintains its own event loop outside the browser event loop to do dirty checking and make sure data is in sync. It will check all known objects for changes on every loop tick. This is done asynchronously. Because this loop is maintained by Angular, you can flush the queue of any outstanding request or pending change at any time, meaning you can test async code in a synchronous manner.

The test runner Karma, makes testing directives exceptionally easy. It transparently loads your templates as scripts and exposes them as Angular modules. You can use the same concept to package your app for production.

more...
No comment yet.