Exportar e Importar Funciones entre documentos en Javascript

Exportar:

romanNumerals.js

export function romanNumerals(){
        var numerals = [
            {value: 4, numeral: "IV"},
            {value: 1, numeral: "I"},
        ];

        function fromNumber(number) {
            var result = "";
            numerals.forEach(function (item) {
                for (; number >= item.value; number -= item.value) {
                    result += item.numeral;
                }

            });
            return result;
        };


        return {
            fromNumber,
        }
}

module.exports = romanNumerals;
export default function romanNumerals(){
        var numerals = [
            {value: 4, numeral: "IV"},
            {value: 1, numeral: "I"},
        ];

        function fromNumber(number) {
            var result = "";
            numerals.forEach(function (item) {
                for (; number >= item.value; number -= item.value) {
                    result += item.numeral;
                }

            });
            return result;
        };


        return {
            fromNumber,
        }
}

Importar:

spec.js

import romanNumerals from "../src/romanNumerals";

describe("test de prueba", function () {
    it("verdadero es verdadero", function () {
        expect(true).toBeTruthy();
    });

    it("converts numbers to Roman numerals", function () {
        expect(romanNumerals().fromNumber(1)).toBe("I");
        expect(romanNumerals().fromNumber(2)).toBe("II");
        expect(romanNumerals().fromNumber(3)).toBe("III");
        expect(romanNumerals().fromNumber(4)).toBe("IV");
        // expect(romanNumerals().fromNumber(2648)).toBe("MMDCXLVIII");
    });


});