好多天没写了,也不知道这段时间在忙些啥,看看ES2015,没看出个刚有点头绪,又被叫去修项目出现的bug,只能暂时ES2015,不过对nodeJS,ES2015这些东西的联系也模模糊糊的知道了些方向
最近项目中的下拉刷新和上拉加载使用iscroll封装dirctive弄了几天才总算是整合进项目里面了,对于在期间出现的一些问题还是总结一下的好,毕竟花了那么多时间去理解

direction 中的scope的理解误区

  1. directive中在没有申明scope或者申明scope:true时,directive中的scope和父级中的$scope是继承并双向绑定关系
  2. directive封装时,尽量只封装JS而不封装HTML,减少重复工

unit test

安装依赖
npm install karma –save-dev
npm install -g karma-cli
npm install karma-jasmine karma-chrome-launcher –save-dev

Writing Tests

touch tests/calculator.controller.test.js
describe(‘calculator’, function () {

  beforeEach(module('calculatorApp'));

  var $controller;

  beforeEach(inject(function(_$controller_){
    $controller = _$controller_;
  }));

  describe('sum', function () {
		it('1 + 1 should equal 2', function () {
			var $scope = {};
			var controller = $controller('CalculatorController', { $scope: $scope });
			$scope.x = 1;
			$scope.y = 2;
			$scope.sum();
			expect($scope.z).toBe(3);
		});	
	});

});

Configuring test

karma init karma.conf.js
answer about “What is the location of your source and test files ?”
Enter the following value:
tests/*.test.js

download the angular and angular mock libraries and replace config with this section:
files: [
‘lib/angular.min.js’,
‘lib/angular-mocks.js’,
‘app/.js’,
‘tests/
.js’
],

Writing controller

angular.module('calculatorApp', []).controller('CalculatorController', function CalculatorController($scope) {
  $scope.sum = function() {
    $scope.z = $scope.x + $scope.y;
  };
});

start test

npm test

参考文档

Getting started with Karma for AngularJS Testing