Giter Site home page Giter Site logo

duck-angular's Introduction

duck-angular

Guides to use this are at http://avishek.net/blog/?p=1202 and http://avishek.net/blog/?p=1188.

A container for bootstrapping and testing AngularJS views and controllers in memory: no browser or external process needed.

duck-angular is available as a Bower package. Install it using bower 'install duck-angular'.

Include it using RequireJS' define(). Your controller/service/object initialisation scripts need to have run before you use Duck-Angular. Put them in script tags, or load them using a script loader like RequireJS or Inject.

Use it in your tests, like so:

// Using Mocha-as-Promised in this example
define(["app", "duckAngular"], function(Duck) { // app.js defines controllers, services, etc.
  describe("Some Page", function() {
    it("can show error message for non-numeric input", function() {
      var container = Duck.bootstrap("YourApp"); // Name of your module
      var dependencies = {service: {}}; // Partially or fully mocked service
      var preRenderBlock = function(scope) {}; // Anything you want to do before template is bound to scope, like setting up scope watches, etc. 
      container.mvc("SomeController", "templates/some-template.html", dependencies, preRenderBlock, {dontWait: false}).then(function(mvc) {
        console.log("Loaded all the good stuff");
        var controller = mvc.controller;
        var view = mvc.view;
        var scope = mvc.scope;
        var dom = new Duck.DOM(view, scope);
        var interaction = new Duck.UIInteraction(dom);
        expect(dom.element("#errorMsg").css("display")).to.eql("none");
        var theBox = view.find("#someTextBox");
        dom.interactWith("#someTextBox", "Some Wrong Data");
        // For when you need to wait on some function anywhere to complete before making certain
        // assertions. The example below is for a function that returns a Q promise. For sync functions,
        // use waitForSync() instead of waitFor()
        return interaction.with("#submit_details").waitFor(scope, "submitDetails").then(function() {
            expect(dom.element("#errorMsg").css("display")).to.eql("");
        });
      });
    });
  });
});

duck-angular's People

Contributors

asengupta avatar

Watchers

 avatar  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.