Home / File/ apiAsyncComponent.spec.ts — vue Source File

apiAsyncComponent.spec.ts — vue Source File

Architecture documentation for apiAsyncComponent.spec.ts, a typescript file in the vue codebase. 3 imports, 0 dependents.

File typescript CompilerSFC StyleProcessor 3 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  328674a0_b559_b2a2_c327_3e381aaf54f7["apiAsyncComponent.spec.ts"]
  c5601857_7faf_30c6_efca_20de90db006c["vue"]
  328674a0_b559_b2a2_c327_3e381aaf54f7 --> c5601857_7faf_30c6_efca_20de90db006c
  6a13c450_be5a_326d_7e2d_c1d429be7e83["v3"]
  328674a0_b559_b2a2_c327_3e381aaf54f7 --> 6a13c450_be5a_326d_7e2d_c1d429be7e83
  907f4994_ea28_43b1_7976_0db9f0e97637["component"]
  328674a0_b559_b2a2_c327_3e381aaf54f7 --> 907f4994_ea28_43b1_7976_0db9f0e97637
  style 328674a0_b559_b2a2_c327_3e381aaf54f7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import Vue from 'vue'
import { defineAsyncComponent, h, ref, nextTick, defineComponent } from 'v3'
import { Component } from 'types/component'

const timeout = (n: number = 0) => new Promise(r => setTimeout(r, n))

const loadingComponent = defineComponent({
  template: `<div>loading</div>`
})

const resolvedComponent = defineComponent({
  template: `<div>resolved</div>`
})

describe('api: defineAsyncComponent', () => {
  afterEach(() => {
    Vue.config.errorHandler = undefined
  })

  test('simple usage', async () => {
    let resolve: (comp: Component) => void
    const Foo = defineAsyncComponent(
      () =>
        new Promise(r => {
          resolve = r as any
        })
    )

    const toggle = ref(true)

    const vm = new Vue({
      render: () => (toggle.value ? h(Foo) : null)
    }).$mount()

    expect(vm.$el.nodeType).toBe(8)

    resolve!(resolvedComponent)
    // first time resolve, wait for macro task since there are multiple
    // microtasks / .then() calls
    await timeout()
    expect(vm.$el.innerHTML).toBe('resolved')

    toggle.value = false
    await nextTick()
    expect(vm.$el.nodeType).toBe(8)

    // already resolved component should update on nextTick
    toggle.value = true
    await nextTick()
    expect(vm.$el.innerHTML).toBe('resolved')
  })

  test('with loading component', async () => {
    let resolve: (comp: Component) => void
    const Foo = defineAsyncComponent({
      loader: () =>
        new Promise(r => {
          resolve = r as any
        }),
      loadingComponent,
// ... (182 more lines)

Domain

Subdomains

Functions

Dependencies

  • component
  • v3
  • vue

Frequently Asked Questions

What does apiAsyncComponent.spec.ts do?
apiAsyncComponent.spec.ts is a source file in the vue codebase, written in typescript. It belongs to the CompilerSFC domain, StyleProcessor subdomain.
What functions are defined in apiAsyncComponent.spec.ts?
apiAsyncComponent.spec.ts defines 1 function(s): timeout.
What does apiAsyncComponent.spec.ts depend on?
apiAsyncComponent.spec.ts imports 3 module(s): component, v3, vue.
Where is apiAsyncComponent.spec.ts in the architecture?
apiAsyncComponent.spec.ts is located at test/unit/features/v3/apiAsyncComponent.spec.ts (domain: CompilerSFC, subdomain: StyleProcessor, directory: test/unit/features/v3).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free