++ed by:
ABRAXXA

1 PAUSE user(s)
1 non-PAUSE user(s).

Kevin Jones

NAME

Test::JavaScript - JavaScript Testing Module

SYNOPSIS

    use Test::JavaScript qw(no_plan);

    js_eval_ok("/path/to/MyFile.js");

    js_ok("var obj = new MyFile", "Create a MyFile object");

    js_ok("obj.someFunction = function () { return 'ok' }");

    js_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.

js_eval_ok
  js_eval_ok($filename)

This reads a file and evals it in JavaScript

For example:

    js_eval_ok( "/path/to/some/file.js" );
js_is
js_isnt
  js_is  ( $this, $that, $test_name );
  js_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:

    js_ok("var i = 3");                                 // ok
    js_is("i", 3, "i is 3");                            // ok
    js_is("3", 3, "3 is 3");                            // ok
    js_is("3", 2, "3 is 2");                            // not ok

    js_ok("function three () { return 3 }");            // ok
    js_is("three()", 3);                                // ok
    js_is("three()", 4);                                // not ok

    js_isnt("3", 4, "3 is not 4");                      // ok
js_ok
  js_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:

    js_ok("var i = 3");                                     // ok
    js_ok("true", "true is true");                          // ok
    js_ok("1 == 2", "1 is equal to 2");                     // not ok
    js_ok("false", "false is false");                       // not ok
    js_ok("var array = ['one','two',non_existing_var];")    // not ok
diag
  js_ok("var myval = 3; diag('the variable myval is ' + myval)");

This subroutine simply logs the parameters passed as a comment

AUTHORS

Kevin Jones, <kevinj at cpan.org>

COPYRIGHT

Copyright 2006 Kevin Jones, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 81:

'=item' outside of any '=over'

Around line 199:

You forgot a '=back' before '=head1'




Hosting generously
sponsored by Bytemark