Skip to content

Instantly share code, notes, and snippets.

@klipstein
Created November 5, 2012 21:44
Show Gist options
  • Save klipstein/4020539 to your computer and use it in GitHub Desktop.
Save klipstein/4020539 to your computer and use it in GitHub Desktop.
Execute Jasmine Tests within BonsaiJS runner context
require([], function() {
describe('bar', function() {
// ...
});
});
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" href="lib/jasmine-core/jasmine.css">
<style>
#bonsai-player {
position: absolute;
visibility: hidden;
}
</style>
<!-- or your local bonsaijs -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/bonsai/0.4/bonsai.min.js"></script>
<script src="lib/jasmine-core/jasmine.js"></script>
<script src="lib/jasmine-core/jasmine-html.js"></script>
<script src="lib/jasmine-core/jasmine.junit-reporter.js"></script>
</head>
<body>
<div id="bonsai-player"></div>
<script>
bonsai.setup({
// required to access the parent context from within runner.js
runnerContext: bonsai.IframeRunnerContext,
}).run(document.getElementById('bonsai-player'), {
urls: [
'lib/requirejs/require.js',
'runner.js' // see below
]
});
</script>
</body>
</html>
// copy jasmine properties to internal bonsai scope
jasmine = parent.jasmine;
afterEach = parent.afterEach;
beforeEach = parent.beforeEach;
describe = parent.describe;
it = parent.it;
expect = parent.expect;
spyOn = parent.spyOn;
xit = parent.xit;
runs = parent.runs;
waitsFor = parent.waitsFor;
xdescribe = parent.xdescribe;
waitForAsync = parent.waitForAsync;
require.config({
paths: {}
});
require([
'foo-spec.js'
// your other specs
], function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.execute();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment