UNPKG

tslint-clean-code

Version:
32 lines 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var TestHelper_1 = require("./TestHelper"); var noForEachPushRule_1 = require("../noForEachPushRule"); var FAILURE_STRING = noForEachPushRule_1.Rule.FAILURE_STRING; describe('noForEachPushRule', function () { var ruleName = 'no-for-each-push'; it('should pass using Array.prototype.map', function () { var script = "\n const arr1 = [1,2,3];\n const results = arr1.map(item => item * 2);\n "; TestHelper_1.TestHelper.assertViolations(ruleName, script, []); }); it('should fail using Array.prototype.push nested within Array.prototype.forEach', function () { var script = "\n const arr1 = [1,2,3];\n const results = [];\n arr1.forEach(item => {\n const newValue = item * 2;\n results.push(newValue);\n });\n "; TestHelper_1.TestHelper.assertViolations(ruleName, script, [ { failure: FAILURE_STRING, name: 'file.ts', ruleName: ruleName, ruleSeverity: 'ERROR', startPosition: { character: 13, line: 4, }, }, ]); }); it('should pass using Array.prototype.push nested within Array.prototype.forEach with an If Statement', function () { var script = "\n const arr1 = [1,2,3];\n const results = [];\n arr1.forEach(item => {\n if (item === 2) {\n return;\n }\n const newValue = item * 2;\n results.push(newValue);\n });\n "; TestHelper_1.TestHelper.assertViolations(ruleName, script, []); }); }); //# sourceMappingURL=NoForEachPushRuleTests.js.map