Git Product home page Git Product logo

ngtestharness's Introduction

#Angular Testing Harness Testing harness for Angular scopes, controllers, and providers. Streamlines the boilerplate created by needing to inject dependencies for Angular Unit Testing. Abstracts other features, and wraps setup and cleanup operations in easy to use functions.

##Modules Loaded By Default

  • ng
  • ngMock
  • ngSanitize

Additional modules, should be included in the modules parameter.

Note: Loading ngCookies adds new functionality to the testing harness. (Please see handleCookie in the API)

##API API

##If using Jasmine

  1. Make sure your SpecRunner includes:

    • Angular
    • Angular Mocks
    • Angular Sanitize
  2. The files should include at least the three angular files above, the harness filepath, the paths to all spec and source files, and the path to your modularized template files.

  1. Open the SpecRunner in a browser.

###Jasmine Modularized Templates Example

angular.module('templates-main', ['template.html']);

angular.module('template.html', []).run(['$templateCache', function($templateCache) {
  $templateCache.put('template.html', '<div class={{class}}>{{message}}</div>');
}]);

###Jasmine SpecRunner Test Example

describe("Load Sample\n", function () {
  var harness = new ngTestHarness([
      'sample',
      'templates-main'
  ]),
  parent={
    message:'Hello'
  };

  it('Expect innerHTML to contain message', function () {
    expect(
      harness.compileElement('<sample-demo message="message"></sample-demo>', parent).html()
    ).toContain('Hello');
  });
});

##If using Karma

  1. Make sure the Karma configuration includes:

    • Angular
    • Angular Mocks
    • Angular Sanitize
  2. The files should include at least the three angular files above, the harness filepath, the paths to all spec and source files, and all template files.

  3. Install the karma-ng-html2js-preprocessor, preferably through npm

  4. Add the 'karma-ng-html2js-preprocessor' plugin to your karma configuration file.

  5. Add a filepath pattern that will include your html templates in the preprocessors section.

  6. Run Karma

plugins: [
    'karma-ng-html2js-preprocessor'
]
preprocessors: {
    "'*.html': 'ng-html2js'"
}

###Karma Test Example (Using Jasmine)

describe("Load Sample\n", function () {
  var harness = new ngTestHarness([
      'sample',
      'template.html'
  ]),
  parent={
    message:'Hello'
  };

  it('Expect innerHTML to contain message', function () {
    expect(
      harness.compileElement('<sample-demo message="message"></sample-demo>', parent).html()
    ).toContain('Hello');
  });
});

##Authors

##Contributors

##License MIT License

##Articles

Copyright (c) 2014-2015 Gaikai Inc. (A Sony Computer Entertainment Company). Visit us at https://gaikai.com/ for more information.

ngtestharness's People

Contributors

davidposin avatar nateferrero avatar nivthefox avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.