Jasmine cheat sheet
by knunery
HTML
<link href="http://blog.bandzarewicz.com/stylesheets/jasmine/jasmine.css" media="screen, projection" rel="stylesheet" type="text/css">
<script>
// Jasmine spec runner, used in jsfiddles
window.execJasmine = function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var trivialReporter = new jasmine.TrivialReporter();
jasmineEnv.addReporter(trivialReporter);
jasmineEnv.specFilter = function(spec) {
return trivialReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
trivialReporter.outerDiv.className += ' show-passed';
}
}
</script>
<script src="https://raw.github.com/pivotal/jasmine/v1.1.0/lib/jasmine-core/jasmine.js"></script>
<script src="https://raw.github.com/pivotal/jasmine/v1.1.0/lib/jasmine-core/jasmine-html.js"></script>
JavaScript
describe('toBeNull', function() {
it('passes if subject is null', function() {
expect(null).toBeNull();
});
it('fails if subject is undefined', function() {
expect(undefined).not.toBeNull();
});
it('fails if subject is no null', function() {
expect({}).not.toBeNull();
});
});
execJasmine();