test-destroy.html 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Test Dependencies</title>
  6. <link rel="stylesheet" href="../dist/reveal.css">
  7. <link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
  8. <script src="../node_modules/qunit/qunit/qunit.js"></script>
  9. </head>
  10. <body style="overflow: auto;">
  11. <div id="qunit"></div>
  12. <div id="qunit-fixture"></div>
  13. <div class="reveal deck1" style="display: none;">
  14. <div class="slides">
  15. <section>Slide content</section>
  16. </div>
  17. </div>
  18. <div class="reveal deck2" style="display: none;">
  19. <div class="slides">
  20. <section>Slide content</section>
  21. </div>
  22. </div>
  23. <script type="module">
  24. import Reveal from '../dist/reveal.esm.js'
  25. import Markdown from '../plugin/markdown/markdown.esm.js'
  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>