How can I test a normal plain javascript file?

Finally I solved with karma + phantomjs + jasmine

with karma I can load the javacript file and tests files adding lines to the karma configuration file this way

// karma.conf.js
files: [
  'hello.js',
  'hello_test.js'
],

and write the tests this way

// test_hello.js
describe('test lib', function () {
  it('test hello', function () {
    expect(hello('world')).toBe('hello world');
  });
});

A example available in github

https://github.com/juanpabloaj/karma_phantomjs_jasmine


For this you could use QUnit.

You would setup a test harness like this:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Test Suite</title>
    <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.10.1.css">
</head>
<body>
    <div id="qunit"></div>
    <div id="qunit-fixture"></div>
    <script src="https://code.jquery.com/qunit/qunit-2.10.1.js"></script>
    <script src="hello.js"></script>
    <script>
        // This can of course be in a separate file
        QUnit.test( "hello test", function( assert ) {
          assert.ok( hello('world') === "hello world", "Passed!" );
        });
    </script>
</body>
</html>