Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest & ES6 module bug #8133

Closed
xgqfrms opened this issue Mar 16, 2019 · 5 comments
Closed

jest & ES6 module bug #8133

xgqfrms opened this issue Mar 16, 2019 · 5 comments

Comments

@xgqfrms
Copy link

xgqfrms commented Mar 16, 2019

jest & ES6 module bug

馃悰 Bug Report

"use strict";

/**
 * 
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2019-01-01
 * 
 * @description sum.js
 * @augments 
 * @example 
 * 
 */

const sum = (a = 0, b = 0) => {
    return a + b;
};

export default sum;

export {
    sum,
};
"use strict";

/**
 * 
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2019-01-01
 * 
 * @description sum.test.js
 * @augments 
 * @example 
 * 
 */


// import { sum } from "./sum";
import * as sum from "./sum";

test("adds 1 + 2 to equal 3", () => {
     expect(sum(1, 2)).toBe(3);
});

error infos

image

OS infos

image

image

@xgqfrms
Copy link
Author

xgqfrms commented Mar 16, 2019

require is OK, but not the way I wanted.

const sum = (a = 0, b = 0) => {
    return a + b;
};

// export default sum;

// export {
//     sum,
// };

module.exports = sum;
// import { sum } from "./sum";
// import * as sum from "./sum";

const sum = require("./sum");

test("adds 1 + 2 to equal 3", () => {
     expect(sum(1, 2)).toBe(3);
});

image

@jeysal
Copy link
Contributor

jeysal commented Mar 16, 2019

This looks like you didn't configure Babel properly.
https://jestjs.io/docs/en/getting-started#using-babel

If you've done that and still encounter issues, please provide a minimal reproduction so we can track down a potential bug.

@xgqfrms
Copy link
Author

xgqfrms commented Mar 18, 2019

@jeysal Thanks a lot!

I'll try it the way you suggested.

@xgqfrms
Copy link
Author

xgqfrms commented Mar 18, 2019

OK

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants