UNPKG

unit.js

Version:

Simple, intuitive and flexible unit testing framework for javascript / Node.js (browser and server). Integrates awesome assertions libraries like Must.js, Should.js, Assert of Node.js, Sinon.js and other friendly features (promise, IoC, plugins, ...).

73 lines (61 loc) 2.15 kB
<!DOCTYPE html> <html> <head> <title>Unit.js tests in the browser with Mocha</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="mocha.css" /> </head> <body> <h1>Unit.js tests in the browser with Mocha</h1> <div id="mocha"></div> <script src="mocha.js"></script> <script src="unit.js"></script> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha256-pasqAKBDmFT4eHoN2ndd6lN370kFiGUFyTiUHWhU7k8=" crossorigin="anonymous"></script> <script> mocha.setup('bdd'); </script> <script src="tests-unit.js"></script> <script> var runner = mocha.run(); //* (Un)comment if you want display the stats in the header runner.on('test end', function() { 'use strict'; if(!$('#mocha-stats').has('li.assertions').length) { $('#mocha-stats') .prepend('<li><strong>Test cases:</strong></li>') .append( '<li>for</li>' + '<li class="assertions">' + '<em>' + unitjs.stats.total.assertions + '</em> ' + '<a href="#assertions-stats">assertions:</a> </li>' ) ; } $('#mocha-stats li.assertions em').text(unitjs.stats.total.assertions); }); //*/ runner.on('end', function() { 'use strict'; var total = unitjs.stats.total.assertions; var details = ''; $('#mocha-stats li.assertions em').text(total); for(var name in unitjs.stats.assertions) { details += '<tr>' + '<td>'+ name + '</td>' + '<td><em>'+ unitjs.stats.assertions[name] +'</em></td>' + '</tr>'; } $('body').append('<div id="assertions-stats">' + '<h2>Assertions stats</h2>' + '<p>Total assertions executed: <em>' + total + '</em></p>' + '<h3>Details:</h3><table>'+ details + '</table></div>' ); }); </script> </body> </html>