1. The entire project file is divided into build,spec,src three folders, package.json,gruntfile.js
2. Because the source file is packaged in grunt, the source file to be compiled is output as knockoutjs.js, according to the readme.md file. Installation
npm install-g grunt-cliNPM InstallGruntThe resulting file is saved in thebuild/output/Folder.
3. The source code with the test file, is under the Spec folder. You can use PHANTOMJS to run tests, PHANTOMJS (which fully supports the web without the need for browser support, its fast, native support for various web standards: DOM processing, CSS selectors, JSON, Canvas, and SVG.PhantomjsCan be used for page automation, network monitoring , Web screenshot , and no interface test ). You can download it first before installing
http://phantomjs.org/download.html
You can also use PHANTOMJS. Open the spec/runner.html file directly in the browser to view the test cases. Test cases are used
Jasmine to write a test case
Main function contents of the runner.html file under 4.spec
1<script type="Text/javascript">2 (function () {3 varJasmineenv =jasmine.getenv ();4Jasmineenv.updateinterval = -;5 6 varHtmlreporter =NewJasmine. Htmlreporter ();7 Jasmineenv.addreporter (htmlreporter);8Jasmineenv.specfilter =Htmlreporter.specfilter;9 Ten varTestlingparam =/[?&]testling=true/. Test (LOCATION.HREF); One if(Testlingparam) AJasmineenv.addreporter (NewJasmine. Tapreporter ());//For testling CI - Jasmineenv.execute (); - })(); the</script>
Usually this is a fixed notation. The result of the test case is output in the page.
5. Familiar with Jasmine
1. The page needs to reference jasmine these files
<script type="text/javascript" src="Lib/jasmine-1.2.0/jasmine.js "></script> <script type="text/javascript" src="lib/jasmine-1.2.0/ Jasmine-html.js "></script> <!--our Jasmine extensions -- <script type="text/javascript" src="Lib/jasmine.extensions.js" C11>></script>
Test case Writing for 2.Jssmine
A file a describe, several test cases on several it
describe(' A Suit ', function() { Beforeeach(function () {//code executed each time it executes});Aftereach(function () {//Execute code after it is finished});it (' A test ', function () {expect (").toequal (");//Ecpect Assertion});});
6. Familiarize yourself with the Knockoutjs API based on the test cases provided by the source code.
Knockoutjs Read source