Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

Overview

JsTester is a library to run javascript tests from within .NET by using phantom.js instead of a UI browser.

Blog Posts

Support

Currently, jasmine.js is the only javascript test framework supported. Tests can be run using any .NET framework and/or runner, but full integration support is only available for xUnit .

Requirements

Phantomjs.exe needs to be available in the path.

Usage

1. Prepare the jasmine spec file

Edit the jasmine runner.html file and add a conditional to only execute the tests on load if running on a UI browser. For example:

  <html>
  <head>
    <title>Jasmine Test Runner</title>
    <!-- Additional resources -->
  </head>
  <body>
     <script type="text/javascript">
         jasmine.getEnv().addReporter(new jasmine.TrivialReporter());

         if (navigator.userAgent.indexOf('PhantomJS') == -1) {
             jasmine.getEnv().execute();
         }
     </script>
  </body>
  </html>

2. Invoke the test from .NET

If you are using xUnit you can use the RunWithPhantomjs and JasmineSpec attributes to point to the jasmine spec file. By default, the name of the spec file is inferred from the method name, but it can also be supplied to the JasmineSpec attribute.

  using JsTester.Xunit;
  namespace Tests.Integration
  {
      [RunWithPhantomjs]
      public class MyJasmineTests
      {
          [JasmineSpec]
          public void TestRunner()
          {
          }
      }
  }

Now you can execute this test as part of the regular xUnit run.

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.