expect('count' in instanceProxy).toBe(false)
})
- test('public properties', () => {
+ test('public properties', async () => {
let instance: ComponentInternalInstance
let instanceProxy: any
const Comp = {
expect(instanceProxy.$options).toBe(instance!.type)
expect(() => (instanceProxy.$data = {})).toThrow(TypeError)
expect(`Attempting to mutate public property "$data"`).toHaveBeenWarned()
+
+ const nextTickThis = await instanceProxy.$nextTick(function(this: any) {
+ return this
+ })
+ expect(nextTickThis).toBe(instanceProxy)
})
test('user attached properties', async () => {
$emit: i => i.emit,
$options: i => (__FEATURE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type),
$forceUpdate: i => () => queueJob(i.update),
- $nextTick: () => nextTick,
+ $nextTick: i => nextTick.bind(i.proxy!),
$watch: i => (__FEATURE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP)
} as PublicPropertiesMap)
import { ErrorCodes, callWithErrorHandling } from './errorHandling'
import { isArray } from '@vue/shared'
+import { ComponentPublicInstance } from './componentPublicInstance'
export interface SchedulerJob {
(): void
const RECURSION_LIMIT = 100
type CountMap = Map<SchedulerJob | SchedulerCb, number>
-export function nextTick(fn?: () => void): Promise<void> {
+export function nextTick(
+ this: ComponentPublicInstance | void,
+ fn?: () => void
+): Promise<void> {
const p = currentFlushPromise || resolvedPromise
- return fn ? p.then(fn) : p
+ return fn ? p.then(this ? fn.bind(this) : fn) : p
}
export function queueJob(job: SchedulerJob) {