本文介绍了Mocha JS:如何在规范中重用断言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Mocha bdd进行单元测试.
I'm using Mocha bdd for unit testing.
在我的规范内,多个测试用例使用相同的断言.
Within my specifications, multiple test cases make use of the same assertions.
我想将这些共享的断言放入一个可重用的块中.
I would like to pull these shared assertions out into a reusable block.
我该怎么做?
推荐答案
以下是参数化测试的示例:
Here is an example of parameterized tests:
'use strict';
var assert = require('chai').assert;
var pascalize = require('inflection/pascalize');
var providers = [
{ name: 'Single Word', input: 'commons', output: 'Commons' },
{ name: 'Single Space', input: 'creative commons', output: 'CreativeCommons' },
{ name: 'Single Colon', input: 'creative:commons', output: 'CreativeCommons' },
{ name: 'Double Colon', input: 'creative::commons', output: 'CreativeCommons' },
{ name: 'Single Slash', input: 'creative/commons', output: 'CreativeCommons' },
{ name: 'Space & Dots', input: 'creative commons...', output: 'CreativeCommons' },
];
describe('pascalize', function () {
providers.forEach(function (provider) {
it(provider.name, function () {
var input = provider.input;
var output = provider.output;
assert(pascalize(input) === output);
});
});
});
这篇关于Mocha JS:如何在规范中重用断言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!