Last active
December 16, 2015 19:19
-
-
Save evilstreak/5484207 to your computer and use it in GitHub Desktop.
Bare bones example of a mocha test suite for markdown-js that'll run in the console and the browser.
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
// require modules under node.js; in a browser they'll already be present | |
if ( typeof chai === "undefined" ) { var chai = require( "chai" ); } | |
if ( typeof markdown === "undefined" ) { var markdown = require( "../lib/markdown" ); } | |
var assert = chai.assert, | |
// test wrapper to pass each a fresh markdown object | |
t = function( fn ) { return function() { fn( new markdown.Markdown() ); }; }; | |
suite( "autolinking", function() { | |
test( "URL", t( function( md ) { | |
assert.deepEqual( md.processInline( "<http://foo.com>" ), | |
[ [ "link", { href: "http://foo.com" }, "http://foo.com" ] ] ); | |
} ) ); | |
test( "Mailto link", t( function( md ) { | |
assert.deepEqual( md.processInline( "<mailto:foo@bar.com>" ), | |
[ [ "link", { href: "mailto:foo@bar.com" }, "foo@bar.com" ] ] ); | |
} ) ); | |
test( "Email address", t( function( md ) { | |
assert.deepEqual( md.processInline( "<foo@bar.com>" ), | |
[ [ "link", { href: "mailto:foo@bar.com" }, "foo@bar.com" ] ] ); | |
} ) ); | |
} ); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Markdown-js Tests</title> | |
<link rel="stylesheet" href="mocha/mocha.css" /> | |
</head> | |
<body> | |
<div id="mocha"></div> | |
<script type="text/javascript" src="mocha/chai.js"></script> | |
<script type="text/javascript" src="../lib/markdown.js"></script> | |
<script type="text/javascript" src="mocha/mocha.js"></script> | |
<script type="text/javascript">mocha.setup( "tdd" );</script> | |
<script type="text/javascript" src="foo.t.js"></script> | |
<script type="text/javascript" src="bar.t.js"></script> | |
<script type="text/javascript"> | |
mocha.checkLeaks(); | |
mocha.run(); | |
</script> | |
</body> | |
</html> |
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
// require modules under node.js; in a browser they'll already be present | |
if ( typeof chai === "undefined" ) { var chai = require( "chai" ); } | |
if ( typeof markdown === "undefined" ) { var markdown = require( "../lib/markdown" ); } | |
var assert = chai.assert, | |
// test wrapper to pass each a fresh markdown object | |
t = function( fn ) { return function() { fn( new markdown.Markdown() ); }; }; | |
suite( "headers", function() { | |
test( "Setext header", t( function( md ) { | |
assert.deepEqual( md.dialect.block.setextHeader( "h1\n===\n\n", [] ), | |
[ [ "header", { level: 1 }, "h1" ] ] ); | |
} ) ); | |
test( "Closing # optional on atxHeader", t( function( md ) { | |
assert.deepEqual( md.dialect.block.atxHeader.call( md, "# h1\n\n"), | |
[ [ "header", { level: 1 }, "h1" ] ] ); | |
} ) ); | |
test( "Atx h2 has right level", t( function( md ) { | |
assert.deepEqual( md.dialect.block.atxHeader.call( md, "## h2\n\n", [] ), | |
[ [ "header", { level: 2 }, "h2" ] ] ); | |
} ) ); | |
test( "Atx and Setext style H2s should produce the same output", t( function( md ) { | |
assert.deepEqual( md.dialect.block.setextHeader.call( md, "h2\n---\n\n", [] ), | |
[ [ "header", { level: 2 }, "h2" ] ] ); | |
} ) ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment