Я пытаюсь запустить модульный тест для следующего кода: Этот код ниже только проверяет, верна ли функция.
Вот код модульного тестирования:
import {encodeLengthHex, toHex } from './utils';
// testing new function
describe('EncodeLengthHex', () => { //mocking the method
test('Testing Function toHex ', () => { // declaring the method
const str = 128 // initial value
const actual = encodeLengthHex(str) // calculate the value
expect(actual).toMatchSnapshot(); // checking whether is true
})
});
Здесьэто основной код:
export function encodeLengthHex(n) {
if (n <= 127) {
return toHex(n);
}
const nHex = toHex(n);
const lengthOfLengthByte = 128 + nHex.length / 2;
return toHex(lengthOfLengthByte) + nHex;
Функция проходит.Но как я могу добавить несколько входов для проверки и сравнения, когда эта функция проходит или не проходит.Спасибо