summaryrefslogtreecommitdiff
path: root/spec/javascripts/syntax_highlight_spec.js.coffee
blob: 6a73b6bf32c1ccdb38e31f6c6018a2c5895d355c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#= require syntax_highlight

describe 'Syntax Highlighter', ->
  stubUserColorScheme = (value) ->
    window.gon ?= {}
    window.gon.user_color_scheme = value

  describe 'on a js-syntax-highlight element', ->
    beforeEach ->
      fixture.set('<div class="js-syntax-highlight"></div>')

    it 'applies syntax highlighting', ->
      stubUserColorScheme('monokai')

      $('.js-syntax-highlight').syntaxHighlight()

      expect($('.js-syntax-highlight')).toHaveClass('monokai')

  describe 'on a parent element', ->
    beforeEach ->
      fixture.set """
        <div class="parent">
          <div class="js-syntax-highlight"></div>
          <div class="foo"></div>
          <div class="js-syntax-highlight"></div>
        </div>
      """

    it 'applies highlighting to all applicable children', ->
      stubUserColorScheme('monokai')

      $('.parent').syntaxHighlight()

      expect($('.parent, .foo')).not.toHaveClass('monokai')
      expect($('.monokai').length).toBe(2)

    it 'prevents an infinite loop when no matches exist', ->
      fixture.set('<div></div>')

      highlight = -> $('div').syntaxHighlight()

      expect(highlight).not.toThrow()