The Jasmine Test statement for JavaScript

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.