UNPKG

@averagehelper/corde

Version:

A simple library for Discord bot tests. (Republished fork to demonstrate a bugfix)

57 lines (56 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExpectOperation = void 0; const interfaces_1 = require("../interfaces"); /** * Entity helper for expectation assertions used for Corde tests * * @description Have 3 generic parameters that serves to define * what are the data that the test function will receive. * * These data will be used in action() command, witch will be implemented * by the inherited class. * */ class ExpectOperation { /** * Initialize the match class with its default values. * * @param cordeBot The instance of CordeBot initialized by the runtime. * @param command The command to execute. * @param isNot Definition if this is a deny test. */ constructor(cordeBot, command, isNot) { this.isNot = isNot; this.command = command; this.cordeBot = cordeBot; this.isEqual = false; } catchExecutionError(error) { this.isEqual = false; if (error instanceof Error) { this.output = error.message; } else { this.output = error; } } generateReport(showExpectAndOutputValue = false) { return new interfaces_1.TestReport({ commandName: this.command, expectation: this.expectation, hasPassed: this.defineIsEqual(this.isEqual), isNot: this.isNot, output: this.output, showExpectAndOutputValue, customReturnMessage: this.customReturnMessage, }); } defineIsEqual(actualIsEqual) { if (this.isNot && !this.forceIsEqualValue) { return !actualIsEqual; } return actualIsEqual; } } exports.ExpectOperation = ExpectOperation;