NAME
Test::JavaScript - JavaScript Testing Module
SYNOPSIS
use Test::JavaScript qw(no_plan);
use_ok("/path/to/MyFile.js");
ok("var obj = new MyFile", "Create a MyFile object");
ok("obj.someFunction = function () { return 'ok' }");
is("obj.someFunction()", "ok");
DESCRIPTION
Test::JavaScript provides a method of unit testing javascript code from within perl. This module uses the JavaScript::SpiderMonkey package to evaluate JavaScript using the SpiderMonkey JavaScript engine.
- use_ok
-
use_ok($filename)
This reads a file and evals it in JavaScript
For example:
use_ok( "/path/to/some/file.js" );
- is
- isnt
-
is ( $this, $that, $test_name ); isnt( $this, $that, $test_name );
This compares two values in JavaScript land. They can be literal strings passed from perl or variables defined earlier.
For example:
ok("var i = 3"); // ok is("i", 3, "i is 3"); // ok is("3", 3, "3 is 3"); // ok is("3", 2, "3 is 2"); // not ok ok("function three () { return 3 }"); // ok is("three()", 3); // ok is("three()", 4); // not ok isnt("3", 4, "3 is not 4"); // ok
- ok
-
ok("var monkey = 3", $test_name);
The expression passed as the first parameter is evaluated as either true or false. The test fails if the expression explicitly returns false, or if a syntax error occurs in JavaScript land
For example:
ok("var i = 3"); // ok ok("true", "true is true"); // ok ok("1 == 2", "1 is equal to 2"); // not ok ok("false", "false is false"); // not ok ok("var array = ['one','two',non_existing_var];") // not ok
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 89:
'=item' outside of any '=over'
=over without closing =back