FountainJS / generator-fountain-webpack

Yeoman 'fountain' generator which handle the Webpack config
http://fountainjs.io
MIT License
4 stars 6 forks source link

Ideas for services and controllers test spec? #52

Closed pablorsk closed 8 years ago

pablorsk commented 8 years ago

Hi!

TODO example is very fine, but just have test for COMPONENTS. How Can I make a tests for Services or Controllers?

Any idea is welcome, sorry for my "no issue".

.yo-rc.json

{
  "generator-fountain-angular1": {
    "version": "0.6.0",
    "props": {
      "framework": "angular1",
      "modules": "webpack",
      "js": "typescript",
      "css": "scss",
      "resolved": "/usr/lib/node_modules/generator-fountain-webapp/node_modules/generator-fountain-angular1/generators/app/index.js",
      "namespace": "fountain-angular1",
      "argv": {
        "remain": [],
        "cooked": [],
        "original": []
      },
      "skip-cache": false,
      "skip-install": false,
      "sample": "todoMVC",
      "router": "uirouter"
    }
  }
}

Example for a component

Part of Footer.spec.ts

import * as angular from 'angular';
import 'angular-mocks';
import {Footer} from './Footer';

describe('Footer component', () => {
  beforeEach(() => {
    angular
      .module('footerComponent', ['app/components/Footer.html'])
      .component('footerComponent', Footer);
    angular.mock.module('footerComponent');
  });

  interface IMyScope extends ng.IScope {
    activeCount: number;
  }

  it('should render correctly', angular.mock.inject(($rootScope: ng.IRootScopeService, $compile: ng.ICompileService) => {
    const $scope: IMyScope = <IMyScope> $rootScope.$new();
    $scope.activeCount = 2;
    const element = $compile('<footer-component active-count="activeCount"></footer-component>')($scope);
    $scope.$digest();
    const footer = element.find('strong');
    expect(footer.html().trim()).toEqual('2');
  }));

Example for Services or Controllers?

Any link for examples for mocha+typescript testing are also welcome. If have Webpack+npm, better!

micaelmbagira commented 8 years ago

Hi, you can find some docs https://docs.angularjs.org/guide/services and https://docs.angularjs.org/guide/unit-testing.