traceScheduler.spec.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {TraceScheduler} from 'sentry/views/performance/newTraceDetails/traceRenderers/traceScheduler';
  2. describe('TraceScheduler', () => {
  3. it('respects priority', () => {
  4. const scheduler = new TraceScheduler();
  5. const highPriority = jest.fn().mockImplementation(() => {
  6. expect(lowPriority).not.toHaveBeenCalled();
  7. });
  8. const lowPriority = jest.fn().mockImplementation(() => {
  9. expect(highPriority).toHaveBeenCalled();
  10. });
  11. // Enquee high priority after low priority
  12. scheduler.on('draw', lowPriority, 10);
  13. scheduler.on('draw', highPriority, 1);
  14. scheduler.dispatch('draw');
  15. });
  16. it('once', () => {
  17. const scheduler = new TraceScheduler();
  18. const cb = jest.fn();
  19. scheduler.once('draw', cb);
  20. scheduler.dispatch('draw');
  21. scheduler.dispatch('draw');
  22. expect(cb).toHaveBeenCalledTimes(1);
  23. });
  24. it('off', () => {
  25. const scheduler = new TraceScheduler();
  26. const cb = jest.fn();
  27. scheduler.on('draw', cb);
  28. scheduler.off('draw', cb);
  29. scheduler.dispatch('draw');
  30. expect(cb).not.toHaveBeenCalled();
  31. });
  32. });