Blame view

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