??????????????$rootScope????????????????????????????????????????????$controller???????????????????????????????????????????????????????????????????????????????????.
????????????????ng?????????????????????????
????ng????????????
??????????????????
????var app = angular.module('myApp'?? []);
????app.directive('aGreatEye'?? function () {
????return {
????restrict: 'E'??
????replace: true??
????template: '<h1>lidless?? wreathed in flame?? {{1 + 1}} times</h1>'
????};
????});
????????????д????????????
describe('Unit testing great quotes'?? function() {
var $compile;
var $rootScope;
// Load the myApp module?? which contains the directive
beforeEach(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");
});
});
????????????????????????????????????????????html?????
????<a-great-eye></a-great-eye>
???????????????????$compile??$rootScope???????????????????html??????????????????????????????_?????ng???????????????_??????ng??????????????????????????????????????????????????????????
????$compile????????????html??????????????????$rootScope????????????????????????????????$rootScope.$digest?????????м???????????????????????????
?????????????????????html??????????????ж??.
????????????????ng??????????????????????
????ng???????????????
????????????????????
????var app = angular.module('myApp'?? []);
????app.filter('interpolate'?? ['version'?? function(version) {
????return function(text) {
????return String(text).replace(/\%VERSION\%/mg?? version);
????};
????}]);
????????д????????????
????describe('filter'?? function() {
????beforeEach(module('myApp'));
????describe('interpolate'?? function() {
????beforeEach(module(function($provide) {
????$provide.value('version'?? 'TEST_VER');
????}));
????it('should replace VERSION'?? inject(function(interpolateFilter) {
????expect(interpolateFilter('before %VERSION% after')).toEqual('before TEST_VER after');
????}));
????});
????});
?????????????????ù???????飬????????version??????interpolate???????????????inject???interpolate?????????????????????????ü???Filter???????????????????????????????У???????????ж??.
???????
???????ò?????????NG?к??????????????????????????????????????????ng????????л?????????????ng???????????????????!