javascript - 即使预期和结果相同,使用 Mocha 测试 String.split() 也会失败
问题描述
我目前正在进入 TDD,我想为一个简单的“String.split()”编写一个测试。
该函数应返回包含在字符串中的单词数组。
export function splitSentence(inputSentence) {
const result = inputSentence.split(' ');
return result;
}
我mocha
用作测试框架和chai
断言。
这是测试。
describe('String Split', () => {
it('should split a string into an array of words', () => {
const inputString = 'This is some text';
const expectedResult = ['This', 'is', 'some', 'text'];
expect(splitSentence(inputString)).to.equal(expectedResult);
});
});
在浏览器控制台中测试所有内容时,它运行良好,因此我确信它会通过测试。但是它失败并显示以下错误消息。
AssertionError: expected [ 'This', 'is', 'some', 'text' ] to equal [ 'This', 'is', 'some', 'text' ]`
查看错误消息后,它们似乎都是平等的,所以我目前想知道这里出了什么问题。
感谢您的帮助。
解决方案
推荐阅读
- performance - 从 Ubuntu 迁移到 Centos 7 后磁盘性能不佳
- python - Replacing for-loop with better alternatives in panda dataframes for similarity measurement
- php - 如何获取条件 HTML 字段值
- java - 每当在 Android Kotiln 中的搜索过滤器上搜索时,列表都不会显示在 RecyclerView 中
- powershell - `Start-Process` 找不到 PATH 中存在的文件,即使给定了文件的绝对路径
- javascript - Firebase 存储 - 获取实际数据而不是 downloadURL
- jquery - 如何更改 node.js 中的日期格式
- python - Python:如何使用 for 循环执行我的代码 5 次?
- html - 单击 Angular 8 外部关闭的下拉菜单
- html - Laravel 页面已过期 419