Last active
December 18, 2015 04:08
-
-
Save akimboyko/5723024 to your computer and use it in GitHub Desktop.
Sample for Mocha that supports both NodeJs Mocha runner and RequireJs + Browsers + LiveReload
This file contains hidden or 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
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Mocha Tests</title> | |
| <link rel="stylesheet" href="css/mocha.css" /> | |
| </head> | |
| <body> | |
| <div id="mocha"></div> | |
| <script src="scripts/require.js"></script> | |
| <script> | |
| require.config({ | |
| paths: { | |
| mocha: 'scripts/mocha', | |
| chai: 'scripts/chai', | |
| test: 'test/test' | |
| } | |
| }); | |
| require(['require', 'mocha'], function(require) { | |
| mocha.setup('bdd'); | |
| require(['chai', 'test'], function() { | |
| //mocha.checkLeaks(); | |
| mocha.run(); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or 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
| var should = require('chai').should(); | |
| describe('Array', function() { | |
| describe('#indexOf()', function() { | |
| it('should return -1 when the value is not present', function() { | |
| [1,2,3].indexOf(5).should.equal(-1); | |
| [1,2,3].indexOf(0).should.equal(-1); | |
| }) | |
| }), | |
| describe('#indexOf()', function(){ | |
| it('should return item position when the value is not present', function() { | |
| [1,2,3].indexOf(1).should.equal(0); | |
| [1,2,3].indexOf(3).should.equal(2); | |
| }) | |
| }) | |
| }); | |
| function User(name) { | |
| this.save = function(callback) { | |
| callback(); | |
| } | |
| } | |
| describe('User', function() { | |
| beforeEach(function() { | |
| //console.log('before each'); | |
| }), | |
| describe('#save()', function() { | |
| it('should save without error', function(done) { | |
| var user = new User('Test'); | |
| user.save(done); | |
| }) | |
| }), | |
| describe('#load()', function() { | |
| it('should load without error') | |
| }) | |
| }); | |
| describe('Array', function() { | |
| describe('#indexOf()', function() { | |
| it('should return -1 when not present', function() { | |
| [1,2,3].indexOf(5).should.equal(-1); | |
| }) | |
| }) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment