Created
October 30, 2012 08:56
-
-
Save pawelpabich/3979105 to your computer and use it in GitHub Desktop.
Java Script unit testing with YUI Test and Jack mocking framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="jack.js" /> | |
JST = JSUnitTesting; | |
YUI().use("node", "console", "test", function (Y) { | |
var validation_tests = new Y.Test.Case({ | |
name: "Validation tests", | |
"validation should fail when both custom and | |
"predefined reasons are selected": function () { | |
var reasons = [true, false, true]; | |
var result = JST.validate(reasons, "content"); | |
Y.Assert.isFalse(result); | |
}, | |
"validation should succeed when only custom reason is selected": function () { | |
var reasons = [false, false, false]; | |
var result = JST.validate(reasons, "content"); | |
Y.Assert.isTrue(result); | |
}, | |
"validation should fail when none of the reasons is selected": function () { | |
var reasons = [false, false, false]; | |
var result = JST.validate(reasons, ""); | |
Y.Assert.isFalse(result); | |
}, | |
"validation should succeed when only predefined reasons are selected": function () { | |
var reasons = [true, true, true]; | |
var result = JST.validate(reasons, ""); | |
Y.Assert.isTrue(result); | |
} | |
}); | |
var submission_tests = new Y.Test.Case({ | |
name: "Submission tests", | |
"confirmation should be shown to the user when validation passes and form is about to be submitted": function () { | |
jack(function () { | |
jack.expect("JST.getCustomReason").atLeast(0).returnValue(null); | |
jack.expect("JST.getPredefinedReasons").atLeast(0).returnValue(null); | |
jack.expect("JST.validate").atLeast(0).returnValue(true); | |
jack.expect("JST.notify").once().mock(function (arg) { | |
Y.Assert.areNotEqual(arg.indexOf("Correct"), -1); | |
}); | |
JST.submitForm(); | |
}); | |
} | |
}); | |
var console = new Y.Console({ | |
verbose: true, | |
newestOnTop: false, | |
style: "block", | |
height:"500px" | |
}); | |
console.render('#testLogger'); | |
Y.Test.Runner.add(validation_tests); | |
Y.Test.Runner.add(submission_tests); | |
Y.Test.Runner.run(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment