-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: tests for script setup helpers
- Loading branch information
Showing
2 changed files
with
53 additions
and
4 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,49 @@ | ||
import { | ||
defineComponent, | ||
h, | ||
nodeOps, | ||
render, | ||
SetupContext | ||
} from '@vue/runtime-test' | ||
import { defineEmit, defineProps, useContext } from '../src/apiSetupHelpers' | ||
|
||
describe('SFC <script setup> helpers', () => { | ||
test('should warn runtime usage', () => { | ||
defineProps() | ||
expect(`defineProps() is a compiler-hint`).toHaveBeenWarned() | ||
|
||
defineEmit() | ||
expect(`defineEmit() is a compiler-hint`).toHaveBeenWarned() | ||
}) | ||
|
||
test('useContext (no args)', () => { | ||
let ctx: SetupContext | undefined | ||
const Comp = { | ||
setup() { | ||
ctx = useContext() | ||
return () => {} | ||
} | ||
} | ||
render(h(Comp), nodeOps.createElement('div')) | ||
expect(ctx).toMatchObject({ | ||
attrs: {}, | ||
slots: {} | ||
}) | ||
expect(typeof ctx!.emit).toBe('function') | ||
}) | ||
|
||
test('useContext (with args)', () => { | ||
let ctx: SetupContext | undefined | ||
let ctxArg: SetupContext | undefined | ||
const Comp = defineComponent({ | ||
setup(_, _ctxArg) { | ||
ctx = useContext() | ||
ctxArg = _ctxArg | ||
return () => {} | ||
} | ||
}) | ||
render(h(Comp), nodeOps.createElement('div')) | ||
expect(ctx).toBeDefined() | ||
expect(ctx).toBe(ctxArg) | ||
}) | ||
}) |
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