Skip to content

Commit

Permalink
Integrated with YUI Test
Browse files Browse the repository at this point in the history
  • Loading branch information
keronsen committed Nov 10, 2009
1 parent c0c9984 commit 1aafe1c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/jack.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ function jack() {} // This needs to be here to make error reporting work correct
'isScriptaculous': isScriptaculous,
'isQunit': isQunit,
'isJsTestDriver': isJsTestDriver,
'isYuiTest': isYuiTest,
'report': report,
'disableReporting': function() { reportingEnabled = false; },
'enableReporting': function() { reportingEnabled = true; },
Expand All @@ -472,9 +473,15 @@ function jack() {} // This needs to be here to make error reporting work correct
function isJsTestDriver() {
return window.jstestdriver != null;
}
function isYuiTest() {
var y = window.YAHOO;
return y != null && y.tool != null && y.tool.TestCase != null;
}
function report(message) {
if(!reportingEnabled) { return; }
if(isJsTestDriver()) {
if(isYuiTest()) {
YAHOO.util.Assert.fail(message);
} else if(isJsTestDriver()) {
fail(message);
} else if(isScriptaculous()) {
throw new Error(message);
Expand Down
42 changes: 42 additions & 0 deletions test/test_84_integration_yuitest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@


describe('Integration with YUI Test',{
after_each: function() {
window.YAHOO = null;
}
,
'Should know when YUI Test is in environment': function() {
window.YAHOO = { tool: { TestCase: function() {} } };
value_of(jack.env.isYuiTest()).should_be_true();
}
,
'Should know when YUI Test not is in environment': function() {
value_of(jack.env.isYuiTest()).should_be_false();
}
,
'Should report unmet expectations by calling YAHOO.util.Assert.fail(message)': function() {
var actualMessage = "";
var called = 0;
window.YAHOO = {
tool: {
TestCase: function() {} 
},
util: {
Assert: {
fail: function(message) {
called++;
actualMessage = message;
} 
}
}
};

window.globalFunction = function() {};
jack(function(){
jack.expect("globalFunction").once();
});

value_of(called).should_be(1);
value_of(actualMessage).should_be("Expectation failed: globalFunction() expected exactly 1 time, called 0 times");
}
});
1 change: 1 addition & 0 deletions test/test_all.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<script type="text/javascript" src="test_81_integration_scriptaculous.js"></script>
<script type="text/javascript" src="test_82_integration_qunit.js"></script>
<script type="text/javascript" src="test_83_integration_jstestdriver.js"></script>
<script type="text/javascript" src="test_84_integration_yuitest.js"></script>
<script type="text/javascript" src="test_99_bugfix.js"></script>


Expand Down

0 comments on commit 1aafe1c

Please sign in to comment.