Skip to content

Commit

Permalink
test: restructure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 26, 2021
1 parent 1ff05b4 commit 4b79bac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
20 changes: 0 additions & 20 deletions packages/reactivity/__tests__/readonly.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
reactive,
readonly,
shallowReadonly,
toRaw,
isReactive,
isReadonly,
Expand Down Expand Up @@ -455,23 +454,4 @@ describe('reactivity/readonly', () => {
'Set operation on key "randomProperty" failed: target is readonly.'
).toHaveBeenWarned()
})

// to retain 2.x behavior.
test('should NOT make nested properties readonly', () => {
const props = shallowReadonly({ n: { foo: 1 } })
// @ts-ignore
props.n.foo = 2
expect(props.n.foo).toBe(2)
expect(
`Set operation on key "foo" failed: target is readonly.`
).not.toHaveBeenWarned()
})

test('should allow shallow und normal reactive for same target', () => {
const target = { foo: 1 }
const shallowProxy = shallowReadonly(target)
const normalProxy = readonly(target)

expect(normalProxy).not.toBe(shallowProxy)
})
})
14 changes: 8 additions & 6 deletions packages/reactivity/__tests__/shallowReactive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ describe('shallowReactive', () => {
expect(isReactive(props.n)).toBe(true)
})

test('should allow shallow und normal reactive for same target', () => {
const target = { foo: 1 }
const shallowProxy = shallowReactive(target)
const normalProxy = reactive(target)

expect(normalProxy).not.toBe(shallowProxy)
// #2843
test('should allow shallow und normal reactive for same target', async () => {
const original = { foo: {} }
const shallowProxy = shallowReactive(original)
const reactiveProxy = reactive(original)
expect(shallowProxy).not.toBe(reactiveProxy)
expect(isReactive(shallowProxy.foo)).toBe(false)
expect(isReactive(reactiveProxy.foo)).toBe(true)
})

describe('collections', () => {
Expand Down
12 changes: 11 additions & 1 deletion packages/reactivity/__tests__/shallowReadonly.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isReactive, isReadonly, shallowReadonly } from '../src'
import { isReactive, isReadonly, readonly, shallowReadonly } from '../src'

describe('reactivity/shallowReadonly', () => {
test('should not make non-reactive properties reactive', () => {
Expand Down Expand Up @@ -27,6 +27,16 @@ describe('reactivity/shallowReadonly', () => {
).not.toHaveBeenWarned()
})

// #2843
test('should differentiate from normal readonly calls', async () => {
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)
})

describe('collection/Map', () => {
;[Map, WeakMap].forEach(Collection => {
test('should make the map/weak-map readonly', () => {
Expand Down

0 comments on commit 4b79bac

Please sign in to comment.