First Mocha Test

simple tests with Mocha and Chai

by Marc-André Lafortune

HTML

<link rel="stylesheet" href="https://s3.amazonaws.com/kiddsoftware-jsfiddle/mocha-1.9.0.css">
<script src="https://s3.amazonaws.com/kiddsoftware-jsfiddle/mocha-1.9.0.js"></script>
<script src="	 https://s3.amazonaws.com/kiddsoftware-jsfiddle/chai-1.5.0.js"></script>
<script src="https://s3.amazonaws.com/kiddsoftware-jsfiddle/chai-jquery.js"></script>
<!-- Mocha test output goes here. -->
<div id="mocha"></div>

CSS

p {
    padding: 0;
    margin: 0;
}

JavaScript

// Configure Mocha, telling both it and chai to use BDD-style tests. 
mocha.setup("bdd");
chai.should();

describe('Mocha', function(){
    it('gives meaningfull error message - sync', function(){
        "hello".should.equal("world");
		})
    it('gives unusable error message - async', function(done){
        Promise.resolve(42).then(function() {
          "hello".should.equal("world")
	        done()
        })
    });
  });

// Run all our test suites.  Only necessary in the browser.
mocha.run();