i'm looking to implement 'Yui Test' in my website to use the TDD methodology. I've also installed the yuitest CLI (npm install -g yuitest).
I don't know how organize my files, i thought to leave the js code in my 'www/js/functions.js' file and create a new file 'www/js/tests.js' where to put my tests.
The issue is that i don'w know how connect different files. I'll try to explain.
In my 'www/js/tests.js' file i've this code (by example on website):
var testCase = new Y.Test.Case({
name: "TestCase Name",
//---------------------------------------------
// Special instructions
//---------------------------------------------
_should: {
error: {
testSortArray: true //this test should throw an error
}
},
//---------------------------------------------
// Tests
//---------------------------------------------
testSortArray: function () {
sortArray(12); //this should throw an error
}
});
and in my 'www/js/functions.js' file i've this function:
function sortArray(array) {
if (array instanceof Array){
array.sort();
} else {
throw new TypeError("Expected an array");
}
}
Obviously it didn't works because when i run the test 'yuitest www/js/tests.js' it didn't see my function in 'www/js/functions.js' file.
Obviously if i move the function from 'www/js/functions.js' file to 'www/js/tests.js' file, it works.
But i need to leave separate these files. Any suggestions?
Thanks!
I use a tests.html page to bring in all necessary resources and to execute the tests.
so tests.html will:
You could also probably use the YUI loader to load up your functions.js too, but I've not tried that (largely because my code under test is all YUI modules, so the loader can laod and work with them just fine)