Skip to content

Commit

Permalink
test(reactive): adding missing tests and correcting existing tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiliangnet authored Nov 28, 2021
1 parent da18983 commit 432f620
Show file tree
Hide file tree
Showing 19 changed files with 1,025 additions and 413 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
"build:docs": "dumi build",
"start": "dumi dev",
"test": "jest --coverage",
"test:reactive": "jest packages/reactive",
"test:validator": "jest packages/validator",
"test:core": "jest packages/core",
"test:reactive": "jest packages/reactive/",
"test:validator": "jest packages/validator/",
"test:core": "jest packages/core/",
"test:core:watch": "npm run test:core --- --watch",
"test:schema": "jest packages/json-schema",
"test:schema": "jest packages/json-schema/",
"test:schema:watch": "npm run test:schema --- --watch",
"test:react": "jest packages/react",
"test:shared": "jest packages/shared",
"test:path": "jest packages/path",
"test:react": "jest packages/react/",
"test:shared": "jest packages/shared/",
"test:path": "jest packages/path/",
"test:react:watch": "npm run test:react --- --watch",
"test:vue": "jest packages/vue",
"test:vue": "jest packages/vue/",
"test:vue:watch": "npm run test:vue --- --watch",
"test:reactive-vue": "jest packages/reactive-vue",
"test:reactive-vue": "jest packages/reactive-vue/",
"test:reactive-vue:watch": "npm run test:reactive-vue --- --watch",
"test:antd": "jest packages/antd",
"test:next": "jest packages/next",
"test:antd": "jest packages/antd/",
"test:next": "jest packages/next/",
"test:watch": "jest --watch",
"test:prod": "jest --coverage --silent",
"preversion": "yarn install --ignore-engines && git add -A && npm run build && npm run lint && npm run test",
Expand Down Expand Up @@ -183,4 +183,4 @@
"dependencies": {
"@ant-design/icons": "^4.0.2"
}
}
}
8 changes: 4 additions & 4 deletions packages/reactive/src/__tests__/action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ test('nested action to reaction', () => {
obs.aa = 4
})
})
expect(handler).toBeCalledWith(2)
expect(handler).toBeCalledWith(4)
expect(handler).nthCalledWith(1, 2)
expect(handler).nthCalledWith(2, 4)
expect(handler).toBeCalledTimes(2)
})

Expand Down Expand Up @@ -525,7 +525,7 @@ test('nested action/batch to reaction', () => {
obs.aa = 4
})
})
expect(handler).toBeCalledWith(2)
expect(handler).toBeCalledWith(4)
expect(handler).nthCalledWith(1, 2)
expect(handler).nthCalledWith(2, 4)
expect(handler).toBeCalledTimes(2)
})
24 changes: 14 additions & 10 deletions packages/reactive/src/__tests__/annotations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ test('shallow annotation', () => {
handler(obs.aa)
})
obs.aa = { bb: { cc: 123 } }
expect(isObservable(obs)).toBeTruthy()
expect(isObservable(obs.aa)).toBeFalsy()
expect(isObservable(obs.aa.bb)).toBeFalsy()
expect(isObservable(obs)).toBe(true)
expect(isObservable(obs.aa)).toBe(false)
expect(isObservable(obs.aa.bb)).toBe(false)
obs.aa.bb = 333
obs.cc = 444
expect(handler).toBeCalledTimes(2)
Expand Down Expand Up @@ -67,8 +67,8 @@ test('ref annotation', () => {
handler(obs.value)
})
obs.value = 333
expect(handler).toBeCalledWith(123)
expect(handler).toBeCalledWith(123)
expect(handler).nthCalledWith(1, 123)
expect(handler).nthCalledWith(2, 333)
expect(handler1).toBeCalledTimes(1)
})

Expand Down Expand Up @@ -99,8 +99,8 @@ test('no action annotation', () => {
}, handler)
setData()
expect(handler).toBeCalledTimes(2)
expect(handler).toBeCalledWith([123, undefined], [undefined, undefined])
expect(handler).toBeCalledWith([123, 321], [123, undefined])
expect(handler).nthCalledWith(1, [123, undefined], [undefined, undefined])
expect(handler).nthCalledWith(2, [123, 321], [123, undefined])
})

test('computed annotation', () => {
Expand Down Expand Up @@ -241,12 +241,16 @@ test('computed with computed array length', () => {
handler(obs.isNotEmpty)
handler2(obs.arr2)
})
expect(handler).toBeCalledWith(false)
expect(handler).toBeCalledTimes(1)
expect(handler).lastCalledWith(false)
expect(handler2).toBeCalledTimes(1)
expect(handler2.mock.calls[0][0]).toEqual([])
obs.arr.push(1)
expect(handler).toBeCalledWith(true)
expect(handler).lastCalledWith(true)
expect(handler2.mock.calls[1][0]).toEqual([2])
obs.arr = []
expect(handler).toBeCalledWith(false)
expect(handler).lastCalledWith(false)
expect(handler2.mock.calls[2][0]).toEqual([])
})

test('computed recollect dependencies', () => {
Expand Down
25 changes: 24 additions & 1 deletion packages/reactive/src/__tests__/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,30 @@ test('ArraySet', () => {
const set = new ArraySet()
set.add(11)
set.add(11)
expect(set.value).toEqual([11])
set.add(22)
expect(set.value).toEqual([11, 22])

const handler = jest.fn()
set.forEach(handler)
expect(handler).toBeCalledTimes(2)
expect(handler).nthCalledWith(1, 11)
expect(handler).nthCalledWith(2, 22)
expect(set.value).toEqual([11, 22])

expect(set.has(11)).toBe(true)
set.delete(11)
expect(set.has(11)).toBe(false)
expect(set.value).toEqual([22])

set.clear()
expect(set.value).toEqual([])

const handler1 = jest.fn()
set.add(11)
set.add(22)
set.forEachDelete(handler1)
expect(handler1).toBeCalledTimes(2)
expect(handler1).nthCalledWith(1, 11)
expect(handler1).nthCalledWith(2, 22)
expect(set.value).toEqual([])
})
Loading

0 comments on commit 432f620

Please sign in to comment.