knockoutjs read source code

1. The entire project file is divided into three folders: build, spec, src, package.json, Gruntfile.js

2. Since the source file is packaged with Grunt, the output of the compiled source file is knockoutjs.js, according to the README.md file. Install

npm install -g grunt-cli
 npm install
 grunt
 The generated file is saved in
under the build/output/ folder.

3. The source code has test files under the spec folder. You can run tests using PhantomJS, PhantomJS (it fully supports the web without browser support, its fast, natively supports various web standards: DOM manipulation, CSS selectors, JSON, Canvas, and SVG.  PhantomJS  can be used for  page automation  ,  network monitoring  ,  web page screenshots  , and  no-interface testing  , etc. ). You can download it before installation

http://phantomjs.org/download.html

You can also open the spec/runner.html file directly in the browser to view the test case without phantomjs. The test case is used

Test cases written with jasmine

 4. The main function content of the runner.html file under the spec

 1    <script type="text/javascript">
 2           (function() {
 3             var jasmineEnv = jasmine.getEnv();
 4             jasmineEnv.updateInterval = 500;
 5 
 6             var htmlReporter = new jasmine.HtmlReporter();
 7             jasmineEnv.addReporter(htmlReporter);
 8             jasmineEnv.specFilter = htmlReporter.specFilter;
 9 
10             var testlingParam = /[?&]testling=true/.test(location.href);
11             if (testlingParam)
12                 jasmineEnv.addReporter(new jasmine.TapReporter()); // For Testling CI
13             jasmineEnv.execute();
14           })();
15         </script>

 通常这是固定的写法。会把测试用例的结果输出在页面中。

5.熟悉Jasmine

  1.页面需要引用jasmine 这几个文件

  <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"></script>

  2.Jssmine 的测试用例编写

一个文件一个describe,几个测试用例就几个it

  

describe('A Suit', function() {
  
beforeEach (function(){
    //执行每个it时执行的代码  
  });
afterEach (function(){
  //执行it 结束后执行的代码
  });
  it('a test',function(){
    expect(''). toEqual(''); // ecpect 断言
  });
});

 6.根据源码提供的测试用例熟悉knockoutjs 的API。

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325210269&siteId=291194637