Saturday, 8 April 2017

How to use an angular test file?

I have a test file like what is at the end. I have tried node FILENAME, npm FILENAME, which get me errors. I've also tried npm test which seem to test something else (attached after the testing file). I'm new to angular and looked at the demo but, Im not really sure what I should be doing.

Code from here: https://github.com/vega/vega-lite-ui (not mine)

testing file:

'use strict';

/* global vl:true */

describe('Directive: bookmarkList', function () {
  var element,
    scope;

  afterEach(inject(function(Modals) {
    // Remove any modals registered during the tests
    Modals.empty();
  }));

  beforeEach(module('vlui', function($provide) {
    // mock vega lite
    $provide.constant('vl', vl);
  }));

  beforeEach(inject(function ($rootScope) {
    scope = $rootScope.$new();
    scope.active = true;
  }));

  it('requires a parent modal directive', inject(function ($compile) {
    // This is a side-effect of the modalCloseButton directive inside bookmarkList
    element = angular.element('<bookmark-list></bookmark-list>');
    expect(function() {
      $compile(element)(scope);
    }).to.throw;
    element = angular.element('<modal><bookmark-list></bookmark-list></modal>');
    expect(function() {
      $compile(element)(scope);
    }).not.to.throw;
  }));

  describe('when opened', function() {
    beforeEach(inject(function(Modals, $compile) {
      var template = '<modal id="test-bookmarks"><bookmark-list></bookmark-list></modal>';
      element = $compile(angular.element(template))(scope);
      Modals.open('test-bookmarks');
      scope.$digest();
    }));

    // TODO: Tests that validate the directive works properly
  });
});

npm test results:

START:
09 04 2017 01:03:39.411:WARN [watcher]: Pattern "/Users/me/psa/polestar/src/vendor/*.js" does not match any file.
09 04 2017 01:03:39.522:INFO [karma]: Karma v1.6.0 server started at http://0.0.0.0:9875/
09 04 2017 01:03:39.523:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
09 04 2017 01:03:39.531:INFO [launcher]: Starting browser PhantomJS
09 04 2017 01:03:40.644:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket BU46HqpjWzeEkmYvAAAA with id 72055404
  Service: Spec
    ✔ should be defined
    ✔ functions should be defined
    _removeEmptyFieldDefs
      empty spec
        ✔ should be cleaned
  Directive: configurationEditor
    ✔ should insert form
    ✔ should attach config to scope
  Directive: jsonInput
    ✔ should make hidden element visible
  Directive: lyraExport
    ✔ should make hidden element visible
  Directive: vgSpecEditor
    ✔ should show source code
  Directive: vlSpecEditor
    ✔ should show source code

Finished in 0.26 secs / 0.066 secs

SUMMARY:
✔ 9 tests completed
[01:03:41] Finished 'test' after 2.17 s



via Bren

No comments:

Post a Comment