Skip to content

Instantly share code, notes, and snippets.

@bndynet
Last active March 1, 2017 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bndynet/e77350054294ab080996b96f34745887 to your computer and use it in GitHub Desktop.
Save bndynet/e77350054294ab080996b96f34745887 to your computer and use it in GitHub Desktop.
Example for Angular Unit Test

Example for Angular Unit Test

describe('Unit testing great quotes', function() {
  var $compile,
      $rootScope;

  // Load the myApp module, which contains the directive
  beforeEach(funtction(){
    module('myApp'));
  }

  // Store references to $rootScope and $compile
  // so they are available to all tests in this describe block
  beforeEach(inject(function(_$compile_, _$rootScope_){
    // The injector unwraps the underscores (_) from around the parameter names when matching
    $compile = _$compile_;
    $rootScope = _$rootScope_;
  }));

  it('Replaces the element with the appropriate content', function() {
    // Compile a piece of HTML containing the directive
    var element = $compile("<a-great-eye></a-great-eye>")($rootScope);
    // fire all the watches, so the scope expression {{1 + 1}} will be evaluated
    $rootScope.$digest();
    // Check that the compiled element contains the templated content
    expect(element.html()).toContain("lidless, wreathed in flame, 2 times");
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment