tslint-clean-code
Version:
TSLint rules for enforcing Clean Code
62 lines • 3.84 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var TestHelper_1 = require("./TestHelper");
var tryCatchFirstRule_1 = require("../tryCatchFirstRule");
describe('tryCatchFirstRule', function () {
var ruleName = 'try-catch-first';
it('should pass on with try-catch being top-level of SourceFile', function () {
var script = "\n try {\n } catch (error) {\n }\n ";
TestHelper_1.TestHelper.assertViolations(ruleName, script, []);
});
it('should pass on with try-catch being top-level of FunctionDeclaration', function () {
var script = "\n function () {\n try {\n } catch (error) {\n }\n }\n ";
TestHelper_1.TestHelper.assertViolations(ruleName, script, []);
});
it('should pass on with try-catch being top-level of ArrowFunction', function () {
var script = "\n () => {\n try {\n } catch (error) {\n }\n }\n ";
TestHelper_1.TestHelper.assertViolations(ruleName, script, []);
});
it('should pass on with try-catch being top-level of MethodDeclaration', function () {
var script = "\n class MyClass {\n doStuff() {\n try {\n } catch (error) {\n }\n }\n }\n ";
TestHelper_1.TestHelper.assertViolations(ruleName, script, []);
});
it('should pass on with try-catch being top-level of GetAccessor', function () {
var script = "\n class MyClass {\n get stuff() {\n try {\n } catch (error) {\n }\n }\n }\n ";
TestHelper_1.TestHelper.assertViolations(ruleName, script, []);
});
it('should pass on with try-catch being top-level of SetAccessor', function () {
var script = "\n class MyClass {\n set stuff() {\n try {\n } catch (error) {\n }\n }\n }\n ";
TestHelper_1.TestHelper.assertViolations(ruleName, script, []);
});
it('should fail on with try-catch not being top-level of FunctionDeclaration', function () {
var script = "\n function () {\n if (true) {\n try {\n } catch (error) {\n }\n }\n }\n ";
TestHelper_1.TestHelper.assertViolations(ruleName, script, [
{
failure: tryCatchFirstRule_1.FAILURE_STRING,
name: 'file.ts',
ruleName: 'try-catch-first',
ruleSeverity: 'ERROR',
startPosition: {
character: 21,
line: 4,
},
},
]);
});
it('should fail on with try-catch not being top-level of named FunctionDeclaration', function () {
var script = "\n function funName() {\n if (true) {\n try {\n } catch (error) {\n }\n }\n }\n ";
TestHelper_1.TestHelper.assertViolations(ruleName, script, [
{
failure: tryCatchFirstRule_1.FAILURE_STRING,
name: 'file.ts',
ruleName: 'try-catch-first',
ruleSeverity: 'ERROR',
startPosition: {
character: 21,
line: 4,
},
},
]);
});
});
//# sourceMappingURL=TryCatchFirstRuleTests.js.map