-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(integration-karma): test bare decorator APIs (#4434)
Co-authored-by: Will Harney <[email protected]>
- Loading branch information
1 parent
9e4ea59
commit 27328de
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
packages/@lwc/integration-karma/test/api/decorators/index.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |