JSFiddle - React, Tailwind, and code Playground
by FlavorScape
HTML
<script src="http://daniellmb.github.io/jasmine-run/jasmine-1.3.1-run.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-mocks.js"></script>
JavaScript
angular.module('myApp', [])
.directive('myTestDirective', function () {
return {
restrict: 'E',
scope: {
myBinding: '='
},
replace: true,
template: '<div ng-if="isRendered">TEST</div>',
controller: 'myTestController'
};
})
.controller('myTestController', function($scope) {
$scope.isRendered = true;
});
describe('myTest directive:', function () {
var scope, compile, validHTML;
validHTML = '<div><my-test-directive my-binding="isRendered"></my-test-directive></div>'; //i
beforeEach(module('myApp'));
beforeEach(inject(function($compile, $rootScope){
scope = $rootScope.$new();
scope.isRendered = true;
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.text()).toContain('TEST');
expect(el.children().eq(0).scope()).toBeDefined();
});
});