JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.angularjs.org/1.2.0-rc.2/angular.js"></script>
<script src="http://daniellmb.github.io/jasmine-run/jasmine-1.3.1-run.js"></script>
<script src="http://code.angularjs.org/1.2.0-rc.2/angular-mocks.js"></script>
JavaScript
angular.module('myApp', [])
.directive('myTest', function () {
return {
restrict: 'E',
scope: {},
replace: true,
template: '<div>far boo</div>',
link: function (scope, element, attrs, controller) {
scope.msg = 'bar';
},
controller: function($scope){
$scope.msg = 'foo';
}
};
});
describe('myTest directive:', function () {
var scope, compile, validHTML;
validHTML = '<my-test></my-test>';
beforeEach(module('myApp'));
beforeEach(inject(function($compile, $rootScope){
scope = $rootScope.$new();
compile = $compile;
}));
function create() {
var elem, compiledElem;
elem = angular.element(validHTML);
compiledElem = compile(elem)(scope);
scope.$digest();
return compiledElem;
}
it('should have a scope on root element', function () {
var el = create();
expect(el.scope()).toBeDefined();
expect(el.scope().$id).not.toEqual(scope.$id);
});
it('should have a populated scope', function(){
var el = create();
expect(el.scope().msg).toBeDefined();
expect(el.scope().msg).toEqual('bar');
});
});