events.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* eslint-env node */
  2. /* eslint global-require: 0, func-names: 0, no-shadow: 0 */
  3. "use strict";
  4. const t = require("tap");
  5. let H9Y = null;
  6. t.beforeEach(function setup(done) {
  7. H9Y = require("../hyphenopoly.module");
  8. done();
  9. });
  10. t.afterEach(function tearDown(done) {
  11. H9Y = null;
  12. delete require.cache[require.resolve("../hyphenopoly.module")];
  13. done();
  14. });
  15. t.test("set Event", async function (t) {
  16. await H9Y.config({
  17. "handleEvent": {
  18. /**
  19. * Prevents default event
  20. * @param {Object} e Event
  21. * @returns {undefined}
  22. */
  23. "error": function (e) {
  24. e.preventDefault();
  25. }
  26. },
  27. "require": ["de"]
  28. });
  29. t.end();
  30. });
  31. t.test("set unknown event", async function (t) {
  32. await H9Y.config({
  33. "handleEvent": {
  34. /**
  35. * Prevents default event
  36. * @param {Object} e Event
  37. * @returns {undefined}
  38. */
  39. "fantasy": function (e) {
  40. e.preventDefault();
  41. }
  42. },
  43. "require": ["de"]
  44. });
  45. t.end();
  46. });
  47. t.test("try to overwrite noncancellable event", async function (t) {
  48. await H9Y.config({
  49. "handleEvent": {
  50. /**
  51. * Prevents default event
  52. * @param {Object} e Event
  53. * @returns {undefined}
  54. */
  55. "hpbLoaded": function (e) {
  56. e.preventDefault();
  57. }
  58. },
  59. "require": ["de"]
  60. });
  61. t.end();
  62. });