training.shoppinpal.com
  • Introduction
  • 1. The Ideal Workspace
    • The Perfect Machine
      • For Biz Team
      • For Developers
      • For Designers
    • Setup a machine in the cloud
      • Solution
      • Setup box on Azure
        • Create a machine on Azure
        • Test drive your remote machine
        • Setup Dropbox On Azure
      • Setup box on DigitalOcean
        • Setup UI
        • Shared FileSystem
          • Dropbox
            • Use locally developed node modules in another project
          • sshfs
        • Long Running Sessions
      • Feedback
  • 2. Learning Git
    • Static Code Analysis
  • 3. The Backend
    • Use Containers
    • Setup a loopback project
    • Lockdown
    • Build a better mousetrap
    • The abyss stares back
    • Built-in models
    • Extending built-in models
    • Understanding UserModel
    • Boot Scripts
    • Promises
    • Find roles for current user
    • Loopback Console
    • Current User
  • 4. Multi-tenancy With Loopback
    • What is Multi-Tenancy
    • Architecting with Loopback
    • Define scope for Roles
    • Role Resolvers
    • Access Control For Tenants
    • Better Programming with multi-tenancy
  • 5. The Frontend
    • The Browser
    • Unit Testing
      • Motivation behind this blog
      • How to write a test
      • Karma and Jasmin
      • Writing Tests
    • End-2-End Testing
    • Angular 1.x
    • Angular 2
      • Testing
  • 6. ElasticSearch
    • Better Search with NGram
    • NGram with Elasticsearch
    • Fun with Path Hierarchy Tokenizer
    • Working with Mappings and Analyzers
  • 7. Promises
    • What are Promises
    • Promise Implementations
    • Nuances
    • What should we use
  • 8. Learning Docker
    • Docker Swarm
  • 9. Queues & Workers
    • PHP workers in AWS EBS
    • NodeJS workers in AWS EBS
      • SQS Daemon by AWS
      • SQS Daemon in NodeJS
      • SQS polling by worker
    • Gearman
  • 10. Docker
    • Capabilities
  • Appendix
    • Bug in WebStorm deployments
    • The Perfect Terminal
    • Scalable App Deployment with AWS
    • Chrome Tips & Tricks
    • Host your own Gitbook
    • Gitbook Tips & Tricks
    • How to handle support incidents
    • Dev Resources
    • Debug e2e Tests on CircleCI
    • Logging
    • Authentication Principles
    • Mac
    • nvm
    • Unify testing with npm
      • Debugging Mocha
    • Sequence Diagrams
    • Project Sync via IDE
      • SFTP with WebStorm
      • SFTP with Visual Studio
    • Soft Linking
    • NodeJS Profiling
      • How to find node.js performance optimization killers
    • Setup Packer on Azure
Powered by GitBook
On this page
  • Configuring karma + jasmin for our angular app
  • Introduction to tools
  • Practical fun
  1. 5. The Frontend
  2. Unit Testing

Karma and Jasmin

PreviousHow to write a testNextWriting Tests

Last updated 7 years ago

Configuring karma + jasmin for our angular app

Introduction to tools

Karma is a test runner and it is a direct product from angularJS team. It provides flexibility to test your app in various browsers and is integrated with Jenkins, TravisCI and CircleCI continuous integration tools.

Jasmin is a test behavior driven development framework for testing javascript. It plays very well with karma. Similar to karma jasmin is also recommended as a framework of choice for AngularJS testing. Jasmin is dependency free.

Practical fun

The repo for already has karma packages and its dependencies (karma-jasmine, jasmine-core, karma-chrome-launcher) so a simple npm command is sufficient to setup the project:

git clone https://github.com/Mohammed-Aadil/AngularUnitTestDemo
cd AngularUnitTestDemo
npm install

I have configured package.json to run bower install command on post install of npm packages. While npm is running, you can install karma command line tool in parallel, so open another terminal and run the following command:

npm install -g karma-cli

At this point we have installed karma and jasmin both. We are ready to create our karma configuration file so we can start writing tests. In a terminal, run the following command:

karma init

This command will ask you series of questions, just hit enter to accept defaults. At the end, it will generate a config file for karma: karma.conf. This file should look like:

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine'],
    files: [
    ],
    exclude: [
    ],
    preprocessors: {
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    concurrency: Infinity
  })
}

Note: do not forget to update the files field in karma.conf file for angular and its dependencies.

AngularUnitTestDemo