UNPKG

2.12 kBJavaScriptView Raw
1/**
2 * @fileoverview Helpers to test EventGenerator interface.
3 * @author Toru Nagashima
4 */
5"use strict";
6
7/* global describe, it */
8
9//------------------------------------------------------------------------------
10// Requirements
11//------------------------------------------------------------------------------
12
13const assert = require("assert");
14
15//------------------------------------------------------------------------------
16// Public Interface
17//------------------------------------------------------------------------------
18
19module.exports = {
20
21 /**
22 * Overrideable `describe` function to test.
23 * @param {string} text - A description.
24 * @param {Function} method - A test logic.
25 * @returns {any} The returned value with the test logic.
26 */
27 describe: (typeof describe === "function") ? describe : /* istanbul ignore next */ function(text, method) {
28 return method.apply(this);
29 },
30
31 /**
32 * Overrideable `it` function to test.
33 * @param {string} text - A description.
34 * @param {Function} method - A test logic.
35 * @returns {any} The returned value with the test logic.
36 */
37 it: (typeof it === "function") ? it : /* istanbul ignore next */ function(text, method) {
38 return method.apply(this);
39 },
40
41 /**
42 * Does some tests to check a given object implements the EventGenerator interface.
43 * @param {Object} instance - An object to check.
44 * @returns {void}
45 */
46 testEventGeneratorInterface(instance) {
47 this.describe("should implement EventGenerator interface", () => {
48 this.it("should have `emitter` property.", () => {
49 assert.equal(typeof instance.emitter, "object");
50 assert.equal(typeof instance.emitter.emit, "function");
51 });
52
53 this.it("should have `enterNode` property.", () => {
54 assert.equal(typeof instance.enterNode, "function");
55 });
56
57 this.it("should have `leaveNode` property.", () => {
58 assert.equal(typeof instance.leaveNode, "function");
59 });
60 });
61 }
62};