BigW Consortium Gitlab

syntax_highlight_spec.js 1.62 KB
Newer Older
1
/* eslint-disable space-before-function-paren, no-var, no-return-assign, quotes */
Fatih Acet committed
2

3
require('~/syntax_highlight');
Fatih Acet committed
4 5 6 7 8 9 10 11 12 13 14 15

(function() {
  describe('Syntax Highlighter', function() {
    var stubUserColorScheme;
    stubUserColorScheme = function(value) {
      if (window.gon == null) {
        window.gon = {};
      }
      return window.gon.user_color_scheme = value;
    };
    describe('on a js-syntax-highlight element', function() {
      beforeEach(function() {
16
        return setFixtures('<div class="js-syntax-highlight"></div>');
Fatih Acet committed
17 18 19 20 21 22 23 24 25
      });
      return it('applies syntax highlighting', function() {
        stubUserColorScheme('monokai');
        $('.js-syntax-highlight').syntaxHighlight();
        return expect($('.js-syntax-highlight')).toHaveClass('monokai');
      });
    });
    return describe('on a parent element', function() {
      beforeEach(function() {
26
        return setFixtures("<div class=\"parent\">\n  <div class=\"js-syntax-highlight\"></div>\n  <div class=\"foo\"></div>\n  <div class=\"js-syntax-highlight\"></div>\n</div>");
Fatih Acet committed
27 28 29 30 31 32 33 34 35
      });
      it('applies highlighting to all applicable children', function() {
        stubUserColorScheme('monokai');
        $('.parent').syntaxHighlight();
        expect($('.parent, .foo')).not.toHaveClass('monokai');
        return expect($('.monokai').length).toBe(2);
      });
      return it('prevents an infinite loop when no matches exist', function() {
        var highlight;
36
        setFixtures('<div></div>');
Fatih Acet committed
37 38 39 40 41 42 43 44
        highlight = function() {
          return $('div').syntaxHighlight();
        };
        return expect(highlight).not.toThrow();
      });
    });
  });
}).call(this);