vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
809 B

  1. // test vis.EventBus
  2. var assert = require('assert'),
  3. vis = require('../vis');
  4. var bus = new vis.EventBus();
  5. var received = [];
  6. var id1 = '1';
  7. bus.on('message', function (event, data, source) {
  8. received.push({
  9. event: event,
  10. data: data,
  11. source: source
  12. });
  13. }, id1);
  14. var id2 = '2';
  15. bus.emit('message', {text: 'hello world'}, id2);
  16. bus.on('chat:*', function (event, data, source) {
  17. received.push({
  18. event: event,
  19. data: data,
  20. source: source
  21. });
  22. });
  23. bus.emit('chat:1', null, id2);
  24. bus.emit('chat:2', {text: 'hello world'}, id1);
  25. // verify if the messages are received
  26. assert.deepEqual(received, [
  27. {event: 'message', data: {text: 'hello world'}, source: id2},
  28. {event: 'chat:1', data: null, source: id2},
  29. {event: 'chat:2', data: {text: 'hello world'}, source: id1}
  30. ]);