Skip to content

Commit

Permalink
test(integration-karma): test bare decorator APIs (#4434)
Browse files Browse the repository at this point in the history
Co-authored-by: Will Harney <[email protected]>
  • Loading branch information
nolanlawson and wjhsf authored Aug 5, 2024
1 parent 9e4ea59 commit 27328de
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { api, track, wire } from 'lwc';
48 changes: 48 additions & 0 deletions packages/@lwc/integration-karma/test/api/decorators/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// This facade is used because the compiler will throw `IS_NOT_DECORATOR` if it detects a decorator
// imported from 'lwc' used as a non-decorator. But it can't detect when those same functions are
// re-exported from a facade!
import { api, track, wire } from './facade.js';

describe('decorator APIs used as non-decorators', () => {
it('api() throws error', () => {
expect(api).toThrowError(
process.env.NODE_ENV === 'production'
? ''
: /@api decorator can only be used as a decorator function/
);
});

it('wire() throws error', () => {
expect(wire).toThrowError(
process.env.NODE_ENV === 'production'
? ''
: /@wire\(adapter, config\?\) may only be used as a decorator/
);
});

it('track() throws error when passed arguments.length !== 1', () => {
const funcs = [
() => track(),
() => track('foo', 'bar'),
() => track('foo', undefined),
() => track('foo', 'bar', 'baz'),
() => track('foo', undefined, 'baz'),
];

for (const func of funcs) {
expect(func).toThrowError(
process.env.NODE_ENV === 'production'
? ''
: /@track decorator can only be used with one argument to return a trackable object, or as a decorator function/
);
}
});

it('track() returns reactive proxy when passed exactly 1 arg', () => {
const obj = { foo: 'bar' };
const proxy = track(obj);

expect(proxy).toEqual(obj);
expect(proxy).not.toBe(obj);
});
});

0 comments on commit 27328de

Please sign in to comment.