Clock.tests.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* global QUnit */
  2. import { Clock } from '../../../../src/core/Clock.js';
  3. export default QUnit.module( 'Core', () => {
  4. QUnit.module( 'Clock', () => {
  5. function mockPerformance() {
  6. const reference = ( typeof global !== 'undefined' ) ? global : self;
  7. reference.performance = {
  8. deltaTime: 0,
  9. next: function ( delta ) {
  10. this.deltaTime += delta;
  11. },
  12. now: function () {
  13. return this.deltaTime;
  14. }
  15. };
  16. }
  17. // INSTANCING
  18. QUnit.test( 'Instancing', ( assert ) => {
  19. // no params
  20. const object = new Clock();
  21. assert.ok( object, 'Can instantiate a Clock.' );
  22. // autostart
  23. const object_all = new Clock( false );
  24. assert.ok( object_all, 'Can instantiate a Clock with autostart.' );
  25. } );
  26. // PROPERTIES
  27. QUnit.todo( 'autoStart', ( assert ) => {
  28. assert.ok( false, 'everything\'s gonna be alright' );
  29. } );
  30. QUnit.todo( 'startTime', ( assert ) => {
  31. assert.ok( false, 'everything\'s gonna be alright' );
  32. } );
  33. QUnit.todo( 'oldTime', ( assert ) => {
  34. assert.ok( false, 'everything\'s gonna be alright' );
  35. } );
  36. QUnit.todo( 'elapsedTime', ( assert ) => {
  37. assert.ok( false, 'everything\'s gonna be alright' );
  38. } );
  39. QUnit.todo( 'running', ( assert ) => {
  40. assert.ok( false, 'everything\'s gonna be alright' );
  41. } );
  42. // PUBLIC
  43. QUnit.todo( 'start', ( assert ) => {
  44. assert.ok( false, 'everything\'s gonna be alright' );
  45. } );
  46. QUnit.todo( 'stop', ( assert ) => {
  47. assert.ok( false, 'everything\'s gonna be alright' );
  48. } );
  49. QUnit.todo( 'getElapsedTime', ( assert ) => {
  50. assert.ok( false, 'everything\'s gonna be alright' );
  51. } );
  52. QUnit.todo( 'getDelta', ( assert ) => {
  53. assert.ok( false, 'everything\'s gonna be alright' );
  54. } );
  55. // OTHERS
  56. QUnit.test( 'clock with performance', ( assert ) => {
  57. if ( typeof performance === 'undefined' ) {
  58. assert.expect( 0 );
  59. return;
  60. }
  61. mockPerformance();
  62. const clock = new Clock( false );
  63. clock.start();
  64. performance.next( 123 );
  65. assert.numEqual( clock.getElapsedTime(), 0.123, 'okay' );
  66. performance.next( 100 );
  67. assert.numEqual( clock.getElapsedTime(), 0.223, 'okay' );
  68. clock.stop();
  69. performance.next( 1000 );
  70. assert.numEqual( clock.getElapsedTime(), 0.223, 'don\'t update time if the clock was stopped' );
  71. } );
  72. } );
  73. } );