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

shallowReactive.spec.ts — vue Source File

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

File typescript 1 imports

Entity Profile

Dependency Diagram

graph LR
  a57fead6_0f53_7e76_f88c_5e5db9dc4310["shallowReactive.spec.ts"]
  d970b406_3424_b00e_55dd_82e98ab5aac2["v3"]
  a57fead6_0f53_7e76_f88c_5e5db9dc4310 --> d970b406_3424_b00e_55dd_82e98ab5aac2
  style a57fead6_0f53_7e76_f88c_5e5db9dc4310 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import {
  isReactive,
  isRef,
  isShallow,
  reactive,
  Ref,
  ref,
  shallowReactive,
  shallowReadonly
} from 'v3'

describe('shallowReactive', () => {
  test('should not make non-reactive properties reactive', () => {
    const props = shallowReactive({ n: { foo: 1 } })
    expect(isReactive(props.n)).toBe(false)
  })

  test('should keep reactive properties reactive', () => {
    const props: any = shallowReactive({ n: reactive({ foo: 1 }) })
    props.n = reactive({ foo: 2 })
    expect(isReactive(props.n)).toBe(true)
  })

  test('isShallow', () => {
    expect(isShallow(shallowReactive({}))).toBe(true)
    expect(isShallow(shallowReadonly({}))).toBe(true)
  })

  // #5271
  test('should respect shallow reactive nested inside reactive on reset', () => {
    const r = reactive({ foo: shallowReactive({ bar: {} }) })
    expect(isShallow(r.foo)).toBe(true)
    expect(isReactive(r.foo.bar)).toBe(false)

    r.foo = shallowReactive({ bar: {} })
    expect(isShallow(r.foo)).toBe(true)
    expect(isReactive(r.foo.bar)).toBe(false)
  })

  // #12597
  test('should not unwrap refs', () => {
    const foo = shallowReactive({
      bar: ref(123)
    })
    expect(isRef(foo.bar)).toBe(true)
    expect(foo.bar.value).toBe(123)
  })

  // #12688
  test('should not mutate refs', () => {
    const original = ref(123)
    const foo = shallowReactive<{ bar: Ref<number> | number }>({
      bar: original
    })
    expect(foo.bar).toBe(original)
    foo.bar = 234
    expect(foo.bar).toBe(234)
    expect(original.value).toBe(123)
  })

// ... (134 more lines)

Dependencies

  • v3

Frequently Asked Questions

What does shallowReactive.spec.ts do?
shallowReactive.spec.ts is a source file in the vue codebase, written in typescript.
What does shallowReactive.spec.ts depend on?
shallowReactive.spec.ts imports 1 module(s): v3.
Where is shallowReactive.spec.ts in the architecture?
shallowReactive.spec.ts is located at test/unit/features/v3/reactivity/shallowReactive.spec.ts (directory: test/unit/features/v3/reactivity).

Analyze Your Own Codebase

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

Try Supermodel Free