• Stars
    star
    118
  • Rank 299,923 (Top 6 %)
  • Language
    JavaScript
  • Created almost 12 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ngMidwayTester Build Status

A pure-javascript integration tester for AngularJS that can be run inline with application code.

Installation

  1. run npm install ng-midway-tester.
  2. include ./node_modules/ngMidwayTester/src/ngMidwayTester.js into your test runner.

Getting Started

Inside of your test spec code, you can use the midway tester like so:

//creating the tester
var tester = ngMidwayTester('moduleName', { /* options */ });

//destroying the tester
tester.destroy();
tester = null;

Be sure to have a new instance of the tester for each spec you're testing.

Example

//this is the module code
angular.module('myModule', ['ngRoute'])
  .config(function($routeProvider) {
    $routeProvider.when('/home', {
      template : 'welcome to {{ title }}',
      controller : 'HomeCtrl'
    });
  })
  .controller('HomeCtrl', function($scope) {
    $scope.title = 'my home page';
  });

//this test spec uses mocha since it has nice support for async testing...
describe('my test spec', function() {
  var tester;
  beforeEach(function() {
    tester = ngMidwayTester('myModule');
  });

  afterEach(function() {
    tester.destroy();
    tester = null;
  });

  it('should have a working home page', function(done) {
    tester.visit('/home', function() {
      expect(tester.path()).to.equal('/home');
      expect(tester.viewElement().html()).to.contain('welcome to my home page');

      var scope = tester.viewScope();
      expect(scope.title).to.equal('my home page');
      done();
    });
  });
});

Downloading Assets

The benefit to using the midway tester is that it will act like an AngularJS application and work around asset mocking. This means that if your code contains a remote XHR call to an asset file then the midway tester will download it just as normal. However, due to the mechanics of Karma, you'll need to assign a proxy which assigns the root path to point to a server hosting your website.

In your Karma settings, it should look something like this:

proxies: {
  //point this to the root of where your AngularJS application
  //is being hosted locally
  '/': 'http://localhost:8844/app'
}

When you start your test runner be sure to have the other server (in this case localhost:8844) running in the background. This can be easily handled in the same terminal window using grunt-contrib-connect and setting keepAlive:false).

Setting the index.html file

Just like an AngularJS application, your test runner expects to have an index.html file. However simply using the same index.html provided in your application code will not work since the JavaScript dependencies are loaded via karma. Therefore to get this to function properly, you need to specify your own HTML to act as the index.html layout code for the test page. This can be accomplished in two ways: using raw HTML directly or referencing a remote HTML file.

Raw HTML

Instantiate the tester using the configuration object using template:

var tester = ngMidwayTester('myApp', {
  template : '<div>' +
             '  <h1>hello</h1>' +
             '  <div id="view-container">' +
             '    <div ng-view></div>' +
             '  </div>' +
             '</div>'
});

Remote HTML Template File

Instantiate the tester using the configuration object using templateUrl:

var tester = ngMidwayTester('myApp', {
  templateUrl : '/test/test-index-template.html'
});

In order to make remote assets work with Karma as expected, you will need to setup a proxy which points the root path to a server pointing it's root to your application directory. This is explained in the previous section in the README.

Default HTML Template Code

The default HTML code for the midway tester looks as follows:

<div><div ng-view></div></div>

This will be used if a configuration object is not provided or either the template properties are not set.

Docs

http://yearofmoo.github.io/ngMidwayTester/docs/classes/ngMidwayTester.html

License

MIT

More Repositories

1

ngAnimate-animate.css

A driver module to make animate.css work with AngularJS 1.2
CSS
225
star
2

angularjs-seed-repo

JavaScript
186
star
3

angular-forms-refactor

JavaScript
75
star
4

AngularJS-Scope.SafeApply

AngularJS $scope.$apply() without the hassle and errors :)
JavaScript
70
star
5

AngularJS-Scope.onReady

a helper wrapper for AngularJS to keep controllers and directives in in-sync in regards to HTTP data.
JavaScript
68
star
6

custom-props

A cross-browser compatible solution for custom CSS styles
JavaScript
44
star
7

ng-tube

JavaScript
37
star
8

directive.js

JavaScript
31
star
9

Vim-Darkmate

A Vim version of the Gedit Darkmate theme
Vim Script
21
star
10

fitc-rtec-angularjs-demo

Ruby
16
star
11

Simple-S3

A super simple wrapper for uploading files to S3 using Ruby
Ruby
15
star
12

MooTools-onhashchange.js

cross browser window.onhashchange event listener
JavaScript
15
star
13

angular-scrapbook

JavaScript
11
star
14

hexo-angular-blog-example

CSS
10
star
15

okej

a bare-metal Result object implementation for TypeScript/JavaScript
TypeScript
9
star
16

Git-Concat

A small tool to concatenate files within a git repo directed by a manifest file
Ruby
9
star
17

angularjs-demo-cms-repo

JavaScript
9
star
18

yearofmoo.github.com

Yearofmoo's github page
CSS
7
star
19

Gistex

A vanilla JavaScript plugin to load and display Github Gist code snippets using AJAX
JavaScript
5
star
20

ng2tube

JavaScript
5
star
21

angular-ttc-app

JavaScript
5
star
22

MooTools-Formular

FormCheck + Form.Validator form validation
JavaScript
5
star
23

MooTools-Event.outerClick

A MooTools event for managing click events performed outside of an Element
JavaScript
4
star
24

angular-rails-seed

JavaScript
4
star
25

URL.Address

A vanilla JavaScript wrapper for URL addressing using HTML5 History, Hashbangs and Anchors
JavaScript
4
star
26

MooSelect

MooSelect is a full-fledged select, multiple select and autocomplete replacement for HTML forms.
JavaScript
4
star
27

Fx.CSS3

A patch designed to make MooTools run all Fx.CSS animations using CSS3 transitions
JavaScript
4
star
28

MooCaptcha

A simple MooTools Class wrapper for the Google Recaptcha AJAX Library
JavaScript
3
star
29

Fx.Rotate

A super optimized cross-browser MooTools rotation Fx plugin
JavaScript
3
star
30

meanstack-presentation

JavaScript
2
star
31

Git-Depend

A super easy way to manage dependencies for a repo without using submodules
Ruby
2
star
32

Fx.Swap

A collection of animated swapping operations for interchangeable HTML elements
JavaScript
2
star
33

fitc-angularjs-spotlight

Slides + Example code for the FITC "Adavnced UI, Plugins and Components in AngularJS" Talk on June 7th 2014
JavaScript
2
star
34

XView.js

A small html parsing tool for custom ajax responses
JavaScript
2
star
35

Searcher.js

A full-featured searching wrapper for various searching operations
JavaScript
2
star
36

MooTools-CursorLoader

An intuitive loading icon which follows the mouse when fired
JavaScript
2
star
37

MooTools-Asset.Extras

A series of helper methods for the MooTools Asset library
JavaScript
2
star
38

1xef.js

An advanced window manager for MooTools
JavaScript
2
star
39

MooTipsy

A dynamic tooltip solution for MooTools
JavaScript
2
star
40

MooTools-Asset.css-patch

A monkey patch class to add support for the onload and onerror events for Asset.css
JavaScript
2
star
41

Github.RepoStatus

2
star
42

MooTools-Scour

A simple utility class which maps html elements to DOM operations in a reusable fashion without the need for custom selectors.
JavaScript
2
star
43

XPartial.js

A simple partial loader complete with asset support
JavaScript
2
star
44

MooModal

My own personal Modal script
JavaScript
2
star
45

MooTools-Formular2

A new version of the MooTools-Formular plugin built atop the MooTools Form.Validator plugin
JavaScript
2
star
46

MooStars

A Star Rating system built with MooTools
JavaScript
2
star
47

MooTools-URI.Format

A simple extension which can be used for the URI class to set URL file formats
JavaScript
2
star
48

demos.yearofmoo.com

All the demo files for all the plugins on yearofmoo.com
JavaScript
2
star
49

XPage.js

A page wrapper for page to page AJAX requests written in MooTools
JavaScript
2
star
50

MooToggles

A simple wrapper for toggle elements written in MooTools
JavaScript
2
star
51

ngPagination

Easy to use pagination for AngularJS
1
star
52

HintLights

JavaScript
1
star
53

grunt-custom-props

JavaScript
1
star
54

fitc-rtec-angularjs-slides

JavaScript
1
star
55

ytCore.js

JavaScript
1
star
56

meanstack-seed-repo

JavaScript
1
star
57

ng-slides

A slidedeck written in AngluarJS
1
star