test-destroy.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Test Dependencies</title>
  6. </head>
  7. <body style="overflow: auto;">
  8. <div id="qunit"></div>
  9. <div id="qunit-fixture"></div>
  10. <div class="reveal deck1" style="display: none;">
  11. <div class="slides">
  12. <section>Slide content</section>
  13. </div>
  14. </div>
  15. <div class="reveal deck2" style="display: none;">
  16. <div class="slides">
  17. <section>Slide content</section>
  18. </div>
  19. </div>
  20. <script type="module">
  21. import 'reveal.css';
  22. import 'qunit/qunit/qunit.css';
  23. import QUnit from 'qunit';
  24. import Reveal from 'reveal.js';
  25. import Markdown from 'reveal.js/plugin/markdown';
  26. QUnit.module( 'Destroy' );
  27. QUnit.test( 'Destruction during initialization', function( assert ) {
  28. let deck = new Reveal( document.querySelector( '.deck1' ) );
  29. deck.initialize({ plugins: [ Markdown ] });
  30. let firstAttemptSuccess = false;
  31. let repeatedAttemptSuccess = false;
  32. try {
  33. deck.destroy();
  34. firstAttemptSuccess = true;
  35. }
  36. catch( error ) {
  37. console.error( error );
  38. }
  39. assert.ok( firstAttemptSuccess, 'was successful' );
  40. // should be able to destroy twice with no side effect
  41. try {
  42. deck.destroy();
  43. repeatedAttemptSuccess = true;
  44. }
  45. catch( error ) {
  46. console.error( error );
  47. }
  48. assert.ok( repeatedAttemptSuccess, 'destroyed twice with no exceptions' );
  49. } );
  50. QUnit.test( 'Destruction after initialization', function( assert ) {
  51. assert.expect( 1 );
  52. let done = assert.async( 1 );
  53. let deck = new Reveal( document.querySelector( '.deck2' ) );
  54. deck.initialize({ plugins: [ Markdown ] }).then(() => {
  55. let wasSuccessful = false;
  56. try {
  57. deck.destroy();
  58. wasSuccessful = true;
  59. }
  60. catch( error ) {
  61. console.error( error );
  62. }
  63. if( wasSuccessful ) {
  64. assert.ok( true, 'was successful' );
  65. }
  66. done();
  67. });
  68. } );
  69. </script>
  70. </body>
  71. </html>