First set up the environment scenario:
General three Directories
System file storage directory for Lib Jasmine
Spec writes a catalog of test cases
SRC directory where the source code is stored (the object being tested)
Specrunner.html Test the entry file.
Entry file Contents:
--------------------------
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"
"Http://www.w3.org/TR/html4/loose.dtd" >
<title>jasmine Spec runner</title>
<link rel= "shortcut icon" type= "Image/png" href= "Lib/jasmine-core/jasmine_favicon.png" >
<link rel= "stylesheet" type= "Text/css" href= "Lib/jasmine-core/jasmine.css" >
<script type= "Text/javascript" src= "Lib/jasmine-core/jasmine.js" ></script>
<script type= "Text/javascript" src= "Lib/jasmine-core/jasmine-html.js" ></script>
<script type= "Text/javascript" src= "Lib/jasmine-core/boot.js" ></script>
<!--include source files here ...-
<script type= "Text/javascript" src= "Js_file_ the source code to be tested. js" ></script>
<!--include spec files here ...-
<script type= "Text/javascript" src= "spec/spec test case file. js" ></script>
<script type= "Text/javascript" >
(function () {
var jasmineenv = jasmine.getenv ();
Jasmineenv.updateinterval = 1000;
var htmlreporter = new Jasmine. Htmlreporter ();
Jasmineenv.addreporter (Htmlreporter);
Jasmineenv.specfilter = function (spec) {
return Htmlreporter.specfilter (spec);
};
var currentwindowonload = window.onload;
Window.onload = function () {
if (currentwindowonload) {
Currentwindowonload ();
}
Execjasmine ();
};
function Execjasmine () {
Jasmineenv.execute ();
}
})();
</script>
<body>
</body>
--------------------------
In the spec directory, write a test case. Write the following content:
-------------------------
Describe ("This was an exmaple suite", function () {
It ("contains spec with an expectation", function () {
Expect (true). ToBe (True);
Expect (false). ToBe (false);
Expect (false). Not.tobe (True);
});
});
-------------------------
Test three examples of use cases.
1,true = = True to pass
2,false = = False to pass
3,false = True to pass
At this point the use case passes.
Reference:
Https://github.com/pivotal/jasmine