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

shallowReadonly.spec.ts — vue Source File

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

File typescript 1 imports

Entity Profile

Dependency Diagram

graph LR
  f127fabb_43da_cef3_f938_b92c86e49d7f["shallowReadonly.spec.ts"]
  6a13c450_be5a_326d_7e2d_c1d429be7e83["v3"]
  f127fabb_43da_cef3_f938_b92c86e49d7f --> 6a13c450_be5a_326d_7e2d_c1d429be7e83
  style f127fabb_43da_cef3_f938_b92c86e49d7f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { isReactive, shallowReadonly, readonly, isReadonly } from 'v3'

describe('reactivity/shallowReadonly', () => {
  test('should be readonly', () => {
    expect(isReadonly(shallowReadonly({}))).toBe(true)
  })

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

  test('should make root level properties readonly', () => {
    const props = shallowReadonly({ n: 1 })
    // @ts-expect-error
    props.n = 2
    expect(props.n).toBe(1)
    expect(
      `Set operation on key "n" failed: target is readonly.`
    ).toHaveBeenWarned()
  })

  // to retain 2.x behavior.
  test('should NOT make nested properties readonly', () => {
    const props = shallowReadonly({ n: { foo: 1 } })

    props.n.foo = 2
    expect(props.n.foo).toBe(2)
    expect(
      `Set operation on key "foo" failed: target is readonly.`
    ).not.toHaveBeenWarned()
  })

  // #2843
  test('should differentiate from normal readonly calls', () => {
    const original = { foo: {} }
    const shallowProxy = shallowReadonly(original)
    const reactiveProxy = readonly(original)
    expect(shallowProxy).not.toBe(reactiveProxy)
    expect(isReadonly(shallowProxy.foo)).toBe(false)
    expect(isReadonly(reactiveProxy.foo)).toBe(true)
  })

  // @discrepancy does not support collections
  // describe('collection/Map', () => {
  //   ;[Map, WeakMap].forEach(Collection => {
  //     test('should make the map/weak-map readonly', () => {
  //       const key = {}
  //       const val = { foo: 1 }
  //       const original = new Collection([[key, val]])
  //       const sroMap = shallowReadonly(original)
  //       expect(isReadonly(sroMap)).toBe(true)
  //       expect(isReactive(sroMap)).toBe(false)
  //       expect(sroMap.get(key)).toBe(val)

  //       sroMap.set(key, {} as any)
  //       expect(
  //         `Set operation on key "[object Object]" failed: target is readonly.`
  //       ).toHaveBeenWarned()
  //     })
// ... (147 more lines)

Dependencies

  • v3

Frequently Asked Questions

What does shallowReadonly.spec.ts do?
shallowReadonly.spec.ts is a source file in the vue codebase, written in typescript.
What does shallowReadonly.spec.ts depend on?
shallowReadonly.spec.ts imports 1 module(s): v3.
Where is shallowReadonly.spec.ts in the architecture?
shallowReadonly.spec.ts is located at test/unit/features/v3/reactivity/shallowReadonly.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