Javascript 如何在摩卡测试替换方法?
我对摩卡很陌生,一直在测试下面的功能。我有以下字符串Javascript 如何在摩卡测试替换方法?,javascript,node.js,mocha.js,chai,Javascript,Node.js,Mocha.js,Chai,我对摩卡很陌生,一直在测试下面的功能。我有以下字符串用连字符替换下划线。我使用以下功能将其替换为将下划线替换为连字符 const type = "replace_underscore_with_hyphen"; type = type.replace(/_/ig, '-'); 但请允许我知道如何在mocha中测试此功能 您可以测试最后一个字符串是否包含连字符,而不是下划线: const replaceUnderscores = () => { const type = "r
用连字符替换下划线。我使用以下功能将其替换为将下划线替换为连字符
const type = "replace_underscore_with_hyphen";
type = type.replace(/_/ig, '-');
但请允许我知道如何在mocha中测试此功能 您可以测试最后一个字符串是否包含连字符,而不是下划线:
const replaceUnderscores = () => {
const type = "replace_underscore_with_hyphen";
return type.replace(/_/ig, '-');
}
it('should replace underscores with hyphen', () => {
const replaced = replaceUnderscores();
expect(replaced).not.toContain('_');
expect(replaced).toContain('-');
});
这取决于这段代码发生的位置。这个问题没有包含它的上下文。