Skip to content

Commit

Permalink
test: add test to confirm export behavior (#4022)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored Feb 28, 2024
1 parent 8a45b74 commit 0539da2
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import Component from 'x/component';
import { createElement } from 'lwc';
import { extractDataIds } from 'test-utils';
import ExportAsDefault from 'x/exportAsDefault';
import ExportAsDefaultWithOtherExports, {
exportee as exporteeAsDefault,
} from 'x/exportAsDefaultWithOtherExports';
import ExportDefaultClassWithOtherExports, {
exportee as exporteeDefaultClass,
} from 'x/exportDefaultClassWithOtherExports';

describe('default export', () => {
it('should work when a module exports non-components as default', () => {
Expand All @@ -13,4 +20,33 @@ describe('default export', () => {
expect(nodes.zero.textContent).toEqual('0');
expect(nodes.string.textContent).toEqual('"bar"');
});

it('should work with `export default class` syntax and other exports', async () => {
expect(exporteeDefaultClass).toBe('foo');
const elm = createElement('x-export-default-class-with-other-exports', {
is: ExportDefaultClassWithOtherExports,
});
document.body.appendChild(elm);
await Promise.resolve();
expect(elm.shadowRoot.querySelector('h1').textContent).toBe('hello world');
});

// TODO [#4020]: support additional syntax for default export
xit('should work with `export { ... as default }` syntax', async () => {
const elm = createElement('x-export-as-default', { is: ExportAsDefault });
document.body.appendChild(elm);
await Promise.resolve();
expect(elm.shadowRoot.querySelector('h1').textContent).toBe('hello world');
});

// TODO [#4020]: support additional syntax for default export
xit('should work with `export { ... as default }` syntax and other exports', async () => {
expect(exporteeAsDefault).toBe('foo');
const elm = createElement('x-export-as-default-with-other-exports', {
is: ExportAsDefaultWithOtherExports,
});
document.body.appendChild(elm);
await Promise.resolve();
expect(elm.shadowRoot.querySelector('h1').textContent).toBe('hello world');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<h1>hello world</h1>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement } from 'lwc';

class ExportAsDefault extends LightningElement {}

export { ExportAsDefault as default };
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<h1>hello world</h1>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { LightningElement } from 'lwc';

const exportee = 'foo';

class ExportAsDefaultWithOtherExports extends LightningElement {}

export { ExportAsDefaultWithOtherExports as default, exportee };
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<h1>hello world</h1>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { LightningElement } from 'lwc';

const exportee = 'foo';

export default class ExportDefaultClassWithOtherExports extends LightningElement {}

export { exportee };

0 comments on commit 0539da2

Please sign in to comment.