chai-param
使用 chai 驗證您方法的參數
快速開始
將它安裝在您的專案中
npm install chai-param
引入並載入它
var chai = require('chai'),
chaiParam = require('chai-param'),
expect = chai.expect,
should = chai.should(),
param = chaiParam.param;
chai.use(chaiParam);
快樂的方法守護 :)
function register(user, pass) {
// using should
param(user, 'user', 'UsersCtl.register').should.not.be.empty;
// or using expect
expect(user).param('user', 'UsersCtl.register')
.to.have.length.above(5)
.and.below(16);
}
設定
可以通過設定 chaiParam.config
物件屬性中的值來配置 Chai-param。例如
var chaiParam = require('chai-param');
chaiParam.config.improveMessages = true;
improveMessages
類型:
Boolean
預設值:true
控制 chai-param
是否應該將 chai 的訊息替換為更具描述性的訊息。因此,例如,取代取得
UserCtl.register: expected 'asdf' to have a length above 5 but got 4
您會得到…
在錯誤訊息中顯示調用者
類型:
Boolean
預設值:true
此選項僅適用於 node,且要求 improveMessages
為 true
。
chaiParam.config.showCaller = true;
disableColors
類型:
Boolean
預設值:false
禁用訊息著色。無趣,但對測試有用。