Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Problem testing component with external template #404

Closed
zoechi opened this issue Jan 9, 2014 · 2 comments
Closed

Problem testing component with external template #404

zoechi opened this issue Jan 9, 2014 · 2 comments

Comments

@zoechi
Copy link
Contributor

zoechi commented Jan 9, 2014

I want to write a unit test (test/src/rating/rating.html/dart) for my <rating> component (lib/rating/rating.dart/html).

void main() {
  useHtmlEnhancedConfiguration();

  ng.Scope _rootScope;
  dom.Element _element;
  ngMock.TestBed _tb;

  setUp(() {
    try {
    ngMock.setUpInjector();

      ngMock.module((ng.Module module) {
        module.install(new RatingModule());
      });

      ngMock.inject((ng.Scope scope, ngMock.TestBed testBed) {
        _rootScope = scope;
        _rootScope['rate'] = 3;
        _tb = testBed;
        _element = _tb.compile('<rating value="rate"></rating>', scope: _rootScope);
        _rootScope.$digest();

      });
      print('setUp done');
    } catch(e) {
      print(e);
    }
  });

The line _element = _tb.compile('<rating value="rate>... fails with

[Unexpected request: GET packages/bootstrap_angular/rating/rating.html

Am I doing something wrong or is this not (yet) supported?

@zoechi
Copy link
Contributor Author

zoechi commented Jan 10, 2014

I changed the components templateUrl to template and got rid of the exception.
The returned element doesn't have any generated children though. It's shadowRoot is empty.
Do you know of an example unit test for a NgComponent that uses this functionality?

@mhevery
Copy link
Contributor

mhevery commented Jan 11, 2014

These kinds of questions should be posted to StackOverflow

Unit tests need to be synchronous. Your uint test is trying to do a GET and hence the error. You need to mock out the GET. Here is a test which does that; https://github.com/angular/angular.dart/blob/master/test/core_dom/http_spec.dart#L69

@mhevery mhevery closed this as completed Jan 11, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants