【发布时间】:2021-05-18 13:22:36
【问题描述】:
我刚开始使用 Chai/Mocha 进行测试。我有一个自定义函数,它使用正则表达式验证字符串(例如)。我想使用这个功能。这是我的代码:
describe('Custom Function', () => {
it('Function 1', () => {
// I'm calling a function here which returns a string, I want to validate that(only as example)
expect(someFunction())
});
});
这可能看起来很简单,但我是新手,很抱歉。现在,关于示例验证函数,我知道我可以使用.to.match(/SOME_REGEX/),但我在其他地方使用相同的函数,我不想重复代码。我的函数将从 API 获取数据并相应地验证测试结果
【问题讨论】:
标签: javascript testing mocha.js chai