JSFiddle - React, Tailwind, and code Playground

by Shanna Barnard

HTML

<script src="http://jasmine.github.io/1.3/lib/jasmine.js"></script>
<script src="http://jasmine.github.io/1.3/lib/jasmine-html.js"></script>
<link rel="stylesheet" href="http://jasmine.github.io/1.3/lib/jasmine.css">
<script src="https://code.angularjs.org/1.2.9/angular.js"></script>
<script src="https://code.angularjs.org/1.2.9/angular-mocks.js"></script>
<div ng-app = 'mainMod'>
    <span class='icon' tool-tip='This is the tooltip data' title></span>
</div>

JavaScript

//--- CODE --------------------------
(function (angular) {
    // Create module
    angular.module('mainMod', [])
        .directive('toolTip', [function () {
        return {
            restrict: 'A',
            scope: {
                theTooltip: '@toolTip'
            },
            link: function (scope, element, attrs) {
                element.tooltip({content : scope.theTooltip, 
                                 tooltipClass: "hover"});
            }
        }
    }]);
})(angular);



// ---SPECS-------------------------

describe('Unit testing tooltip', function () {
    var $compile;
    var $rootScope;
    var $scope;
    var element;
    var isolateScope;

    // Load the myApp module, which contains the directive
    beforeEach(module('mainMod'));

    beforeEach(inject(function (_$compile_, _$rootScope_) {
        $compile = _$compile_;
        $rootScope = _$rootScope_;
        
        //create a new scope here
        $scope     = $rootScope.$new();
        
        //create a directive before each test case
        element = angular.element("<span class='icon' tool-tip='This is the tooltip data'></span>");
        
        //use the current scope has just been created above for the directive
        $compile(element)($scope);
        $scope.$digest();
        
        isolateScope = element.isolateScope();
    }));

    it('should have data in tooltip', function () {
       expect(isolateScope.theTooltip).toBe('This is the tooltip data');
    });
});

// --- Runner -------------------------
(function () {
    var jasmineEnv = jasmine.getEnv();
    jasmineEnv.updateInterval = 1000;

    var htmlReporter = new jasmine.HtmlReporter();

    jasmineEnv.addReporter(htmlReporter);

    jasmineEnv.specFilter = function (spec) {
        return htmlReporter.specFilter(spec);
    };

    var currentWindowOnload = window.onload;

    window.onload = function () {
        if (currentWindowOnload) {
            currentWindowOnload();
        }
       ...