Skip to content

Instantly share code, notes, and snippets.

@dzwarg
Last active December 14, 2015 01:39
Show Gist options
  • Save dzwarg/5007506 to your computer and use it in GitHub Desktop.
Save dzwarg/5007506 to your computer and use it in GitHub Desktop.
Example test setup for JSTest.NET
/*global require:true, assert:true */
require(['processor']);
var processor = require('processor');
function processorExists() {
assert.isNotNull(processor, "'processor' is not defined");
}
/*global define:true */
define('processor', ['module'], function (module) {
'use strict';
var processor = {
config: module.config()
/* ... really awesome code here ... */
};
return processor;
});
using JSTest;
using JSTest.ScriptElements;
using JSTest.ScriptLibraries;
using NUnit.Framework;
namespace JSLib.Test
{
[TestFixture]
public class ProcessorTests
{
[Datapoints]
public readonly TestCase[] LibraryTests = TestCase.LoadFrom(@"..\..\Test\processor-suite.js");
[Theory]
public void Test(TestCase testCase)
{
var script = new TestScript { IncludeDefaultBreakpoint = false };
// Append required JavaScript libraries.
script.AppendBlock(new JsAssertLibrary());
// Append required JavaScript Files.
script.AppendFile(@"..\..\Scripts\require.js");
script.AppendFile(@"..\..\Scripts\processor.js");
script.AppendFile(testCase.TestFile);
// Run 'Test'.
script.RunTest(testCase);
}
}
}
/*global require:true, assert:true */
require(['renderer']);
var renderer = require('renderer');
function rendererExists() {
assert.isNotNull(renderer, "'renderer' is not defined");
}
/*global define:true */
define('renderer', ['processor', 'module'], function (processor, module) {
'use strict';
var renderer = function (options) {
/* ... initialization stuff ... */
renderer.processor = processor || options.processor;
};
renderer.prototype = {
config: module.config()
/* ... module stuff ... */
};
return renderer;
});
using JSTest;
using JSTest.ScriptElements;
using JSTest.ScriptLibraries;
using NUnit.Framework;
namespace JSLib.Test
{
[TestFixture]
public class RendererTests
{
[Datapoints]
public readonly TestCase[] LibraryTests = TestCase.LoadFrom(@"..\..\Test\renderer-suite.js");
[Theory]
public void Test(TestCase testCase)
{
var script = new TestScript { IncludeDefaultBreakpoint = false };
// Append required JavaScript libraries.
script.AppendBlock(new JsAssertLibrary());
// Append required JavaScript Files.
script.AppendFile(@"..\..\Scripts\require.js");
script.AppendFile(@"..\..\Scripts\processor.js");
script.AppendFile(@"..\..\Scripts\renderer.js");
script.AppendFile(testCase.TestFile);
// Run 'Test'.
script.RunTest(testCase);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment