1 | global.chai = require('chai')
|
2 | global.assert = chai.assert
|
3 | global.expect = chai.expect
|
4 | chai.should()
|
5 |
|
6 | beforeEach -> global.sinon = require('sinon').sandbox.create()
|
7 | afterEach -> global.sinon.restore()
|
8 |
|
9 | global.Styledown = require '../index'
|
10 | global.Cheerio = require 'cheerio'
|
11 |
|
12 | before ->
|
13 | @load = (html, options={}) ->
|
14 | @sd = new Styledown(html, options)
|
15 | @html = @sd.toHTML()
|
16 | @$ = Cheerio.load(@html)
|
17 |
|
18 | chai.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 |
|
32 | chai.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 |
|
40 | chai.Assertion.addMethod 'selectors', (val, msg) ->
|
41 | val.forEach @selector.bind(this)
|