Created
August 22, 2011 15:08
-
-
Save maio/1162604 to your computer and use it in GitHub Desktop.
convert tests to jasmine
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
describe("TODO List", function() { | |
beforeEach(function() { | |
storage = new TestCookieStorage; | |
tasks = storage.load_tasks(); | |
users = storage.load_users(); | |
}); | |
it("loads tasks from storage", function() { | |
expect(tasks.length).toEqual(1); | |
}); | |
it("loads users from storage", function() { | |
expect(users.length).toEqual(4); | |
expect(users).toContain("Bartek Vladimir"); | |
}); | |
}); |
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
function test_run () { | |
var tests = [ | |
"storage", | |
] | |
console.log(true, "Test run start."); | |
try { | |
execute_tests_from_array(tests); | |
} | |
catch (error) { | |
console.log(false, error); | |
} | |
} | |
function execute_tests_from_array(tests) { | |
for (var i in tests) { | |
run_test(tests[i]); | |
} | |
} | |
function run_test(test_name) { | |
init_test(); | |
var eval_code = "test_"+test_name+"()"; | |
eval(eval_code); | |
reset_state(); | |
} | |
function init_test() { | |
storage = new TestCookieStorage; | |
tasks = new Array();• | |
tasks = storage.load_tasks(); | |
users = storage.load_users();••••••• | |
} | |
function test_storage() { | |
console.log((tasks.length==1), "Created Task object with test data. Tasks "+ | |
"array length equals 1."); | |
console.log(users.length==4, "Created User object with test data. Users "+ | |
"array length equals 4."); | |
console.log(users[0]=="Bartek Vladimir", "First user's name is as expected.") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment