deps-parser.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. describe('Dependency Parser', function () {
  2. var DepsParser = require('vue/src/deps-parser')
  3. describe('.parse()', function () {
  4. // mock the bidnings...
  5. var bindings = [],
  6. catcher = DepsParser.catcher
  7. for (var i = 0; i < 10; i++) {
  8. mockBinding(i)
  9. }
  10. function mockBinding (i) {
  11. var b = {
  12. id: i,
  13. depId: ~~(Math.random() * i),
  14. deps: [],
  15. subs: [],
  16. compiler: {},
  17. value: {
  18. $get: function () {
  19. if (i > 0) {
  20. catcher.emit('get', bindings[b.depId])
  21. }
  22. }
  23. }
  24. }
  25. bindings.push(b)
  26. }
  27. DepsParser.parse(bindings)
  28. it('should parse the deps correctly', function () {
  29. bindings.forEach(function (b) {
  30. if (b.id === 0) return
  31. var dep = b.deps[0]
  32. assert.strictEqual(dep.id, b.depId)
  33. assert.ok(dep.subs.indexOf(b) > -1)
  34. })
  35. })
  36. })
  37. })