Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commit9e04f6a

Browse files
schipigayyx990803
authored andcommitted
test: add unit tests for core/observer/dep (vuejs#7738)
1 parent6b8516b commit9e04f6a

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
importDepfrom'core/observer/dep'
2+
3+
describe('Dep',()=>{
4+
letdep
5+
6+
beforeEach(()=>{
7+
dep=newDep()
8+
})
9+
10+
describe('instance',()=>{
11+
it('should be created with correct properties',()=>{
12+
expect(dep.subs.length).toBe(0)
13+
expect(newDep().id).toBe(dep.id+1)
14+
})
15+
})
16+
17+
describe('addSub()',()=>{
18+
it('should add sub',()=>{
19+
dep.addSub(null)
20+
expect(dep.subs.length).toBe(1)
21+
expect(dep.subs[0]).toBe(null)
22+
})
23+
})
24+
25+
describe('removeSub()',()=>{
26+
it('should remove sub',()=>{
27+
dep.subs.push(null)
28+
dep.removeSub(null)
29+
expect(dep.subs.length).toBe(0)
30+
})
31+
})
32+
33+
describe('depend()',()=>{
34+
let_target
35+
36+
beforeAll(()=>{
37+
_target=Dep.target
38+
})
39+
40+
afterAll(()=>{
41+
Dep.target=_target
42+
})
43+
44+
it('should do nothing if no target',()=>{
45+
Dep.target=null
46+
dep.depend()
47+
})
48+
49+
it('should add itself to target',()=>{
50+
Dep.target=jasmine.createSpyObj('TARGET',['addDep'])
51+
dep.depend()
52+
expect(Dep.target.addDep).toHaveBeenCalledWith(dep)
53+
})
54+
})
55+
56+
describe('notify()',()=>{
57+
it('should notify subs',()=>{
58+
dep.subs.push(jasmine.createSpyObj('SUB',['update']))
59+
dep.notify()
60+
expect(dep.subs[0].update).toHaveBeenCalled()
61+
})
62+
})
63+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp