-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,42 @@ | ||
var marked = require('../../lib/marked.js'); | ||
const marked = require('../../'); | ||
const HtmlDiffer = require('@markedjs/html-differ').HtmlDiffer; | ||
const htmlDiffer = new HtmlDiffer({ignoreSelfClosingSlash: true}); | ||
|
||
beforeEach(function () { | ||
marked.setOptions(marked.getDefaults()); | ||
|
||
jasmine.addMatchers({ | ||
toRender: function () { | ||
return { | ||
compare: function (spec, expected) { | ||
const result = {}; | ||
const actual = marked(spec.markdown, spec.options); | ||
result.pass = htmlDiffer.isEqual(expected, actual); | ||
|
||
if (result.pass) { | ||
result.message = spec.markdown + '\n------\n\nExpected: Should Fail'; | ||
} else { | ||
var expectedHtml = expected.replace(/\s/g, ''); | ||
var actualHtml = actual.replace(/\s/g, ''); | ||
|
||
for (var i = 0; i < expectedHtml.length; i++) { | ||
if (actualHtml[i] !== expectedHtml[i]) { | ||
actualHtml = actualHtml.substring( | ||
Math.max(i - 30, 0), | ||
Math.min(i + 30, actualHtml.length)); | ||
|
||
expectedHtml = expectedHtml.substring( | ||
Math.max(i - 30, 0), | ||
Math.min(i + 30, expectedHtml.length)); | ||
|
||
break; | ||
} | ||
} | ||
result.message = 'Expected:\n' + expectedHtml + '\n\nActual:\n' + actualHtml; | ||
} | ||
return result; | ||
} | ||
}; | ||
} | ||
}); | ||
}); |