zoukankan      html  css  js  c++  java
  • [Node.js] Introduction to apiCheck.js

    timeoutLog.js:

    var apiCheckFactory = require('api-check');
    
    var myCheck = apiCheckFactory();
    
    module.exports = timeoutLog;
    
    var api = [
      myCheck.number,
      myCheck.shape({
        name: myCheck.string
      }),
      myCheck.func.optional
    ];
    
    function timeoutLog(time, person, callback) {
      myCheck.throw(api, arguments);
    
      setTimeout(function() {
        console.log('Time is up for ' + person.name + '!');
        callback && callback(person);
      }, time);
    }

    index.js:

    // just giving me some space...
    console.log('
    ------
    ');
    
    
    var timeoutLog = require('./timeoutLog');
    
    var person = {
      name: 'Jane'
    };
    
    timeoutLog(300, {name: 'Joe'}, function(thePerson) {
      console.log(
        'Person is the same? ' + (person === thePerson)
      );
    });

    Error message something like:

    Error: apiCheck failed! `Argument 1` passed, `value` at `Argument 2` must be `String`
    
    You passed:
    [
      "wHY+jgNSE0HaoLsMgqkF4uGBX33bf6orJcLVGD0MdFx+tPoPnoJ9EreqOxuUixXoEOI2nGwJb8sXFAyrnXSjMpD98OVj0wg2menNJ65LzEtw3YYBsBZ4yzRtI6PD13zUy+R3S7WIhcWI30V+jZShvP5J2rm4=",
      true
    ]
    
    With the types:
    [
      "string",
      "boolean"
    ]
    
    The API calls for:
    [
      "String",
      "String"
    ]
  • 相关阅读:
    日志模块
    DDT数据驱动
    unittest测试框架
    vim编辑器
    文件夹的管理
    文件内容查看(如查看日志)
    文件的移动和拷贝
    文件的增删改查
    linux基本命令
    测试5--模拟一个在控制台不断按时分秒打印的电子表
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4564106.html
Copyright © 2011-2022 走看看