【发布时间】:2018-12-27 02:18:27
【问题描述】:
试图为以下代码设置单元测试,但我不断得到这个:比较两种不同类型的值。预期的字符串,但收到未定义。作为一个错误
Test :
import {prepadSigned} from './utils';
describe('prepadSigned', () => {test('should prepend `00` to the input <', () => {
const str = '-10';
const actual = prepadSigned(str);
const expected = '00-10';
expect(actual).toEqual(expected);
})
代码:
function prepadSigned(hexStr) {
const msb = hexStr[0];
if (msb < '0' || msb > '7') {
return `00${hexStr}`;
}
return hexStr;
}
我希望单元测试能够通过一些输入/输出。 我不断收到以下信息:
expect(received).toEqual(expected)
Expected value to equal:
"00-10"
Received:
undefined
【问题讨论】:
标签: reactjs unit-testing jestjs