deps-parser.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. describe('UNIT: Dependency Parser', function () {
  2. var DepsParser = require('seed/src/deps-parser')
  3. describe('.parse()', function () {
  4. // mock the bidnings...
  5. var bindings = [],
  6. ob = DepsParser.observer
  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. value: {
  17. $get: function () {
  18. if (i > 0) {
  19. ob.emit('get', bindings[b.depId])
  20. }
  21. }
  22. }
  23. }
  24. bindings.push(b)
  25. }
  26. DepsParser.parse(bindings)
  27. it('should parse the deps correctly', function () {
  28. bindings.forEach(function (b) {
  29. if (b.id === 0) return
  30. var dep = b.deps[0]
  31. assert.strictEqual(dep.id, b.depId)
  32. assert.ok(dep.subs.indexOf(b) > -1)
  33. })
  34. })
  35. })
  36. })