-
Notifications
You must be signed in to change notification settings - Fork 156
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
export default *some functional component* is broken #332
Comments
Thanks for the bug report! Debugging these is super painful. What I do is I can look at this in the near-ish future, but if you want to take a look, happy to help out with debugging. |
@lmiller1990, the problem is on this line: node.add(';exports.default = {...exports.default};') In my case, "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var vue_1 = require("vue");
var component = function () {
return vue_1.h('div', {}, '._.');
};
console.log('Component in MyTest.vue', component);
exports.default = component;
So the solution may look something like this: node.add(`;
if (typeof exports.default === 'function') {
const fn = exports.default;
exports.default = (...args) => fn(...args);
Object.assign(exports.default, fn)
} else {
exports.default = {...exports.default};
}
`) Anyway, what is the reason to copy default export's fields to itself? |
Hi - I completed missed this notification! Sorry. I don't remember how or why I wrote the code like that. Doesn't make much sense - as long as the test suite passes, you can probably remove it. Would you like to make a PR with you fix? I will do a release in the next few days, since we merged a few nice bug fixes lately. I normally just add my test case here. You could add your functional component in here. |
@lmiller1990, i created a PR. Here it is: #335 |
Merged and released https://github.com/vuejs/vue-jest/releases/tag/v5.0.0-alpha.9 |
Repo: https://github.com/0x009922/vue-jest-default-export-issue
Problem
Something goes wrong when i am exporting function as default export from .vue file. It is common case when my component is functional.
MyTest.vue
:MyTest.spec.ts
:And when i have run
jest
, i got this output:In
console.log
results you can see, thatMyTest
component in theMyTest.spec.ts
is not a function. But it is in theMyTest.vue
.The text was updated successfully, but these errors were encountered: