UNPKG

1.09 kBtext/coffeescriptView Raw
1global.chai = require('chai')
2global.assert = chai.assert
3global.expect = chai.expect
4chai.should()
5
6beforeEach -> global.sinon = require('sinon').sandbox.create()
7afterEach -> global.sinon.restore()
8
9global.Styledown = require '../index'
10global.Cheerio = require 'cheerio'
11
12before ->
13 @load = (html, options={}) ->
14 @sd = new Styledown(html, options)
15 @html = @sd.toHTML()
16 @$ = Cheerio.load(@html)
17
18chai.Assertion.addMethod 'htmleql', (val, msg) ->
19 a = Cheerio.load(@_obj, normalizeWhitespace: true).html()
20 b = Cheerio.load(val, normalizeWhitespace: true).html()
21 a = a.replace(/>\s*</g, '><').trim()
22 b = b.replace(/>\s*</g, '><').trim()
23
24 @assert(
25 a == b,
26 'expected #{this} to equal #{exp}',
27 'expected #{this} to not equal #{exp}',
28 b,
29 a,
30 true)
31
32chai.Assertion.addMethod 'selector', (val, msg) ->
33 @assert(
34 @_obj(val).length > 0,
35 "expected $ to have a selector '"+val+"'",
36 "expected $ to not have a selector '"+val+"'",
37 val,
38 @_obj.html())
39
40chai.Assertion.addMethod 'selectors', (val, msg) ->
41 val.forEach @selector.bind(this)