Skip to content

Commit

Permalink
Merge pull request palantir#459 from leeavital/tests/any
Browse files Browse the repository at this point in the history
Add more tests for the <no-any> rule
  • Loading branch information
adidahiya committed Jun 24, 2015
2 parents 3df72a8 + 1a0a193 commit 7f2dd84
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
1 change: 0 additions & 1 deletion test/files/rules/noAny.test.ts

This file was deleted.

10 changes: 10 additions & 0 deletions test/files/rules/noany.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var x: any; // error

function foo(a: any) : any { // 2 errors
return;
}

let a: any = 2, // error
b: any = 4; // error

let {a: c, b: d}: {c: any, d: number} = {c: 99, d: 100}; // error
35 changes: 31 additions & 4 deletions test/rules/noAnyRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,41 @@
*/

describe("<no-any>", () => {
const fileName = "rules/noany.test.ts";
const NoAnyRule = Lint.Test.getRule("no-any");
const fileName = "rules/noAny.test.ts";
const actualFailures = Lint.Test.applyRuleOnFile(fileName, NoAnyRule);

it("const declaration with type of 'any' should not be allowed", () => {
const actualFailures = Lint.Test.applyRuleOnFile(fileName, NoAnyRule);
const expectedFailure = Lint.Test.createFailure(fileName, [1, 8], [1, 11], "type decoration of 'any' is forbidden");
const createFailure = Lint.Test.createFailuresOnFile(fileName, NoAnyRule.FAILURE_STRING);

it("disallows variables with type 'any'", () => {
const expectedFailures = [
createFailure([1, 8], [1, 11]),
createFailure([7, 8], [7, 11]),
createFailure([8, 8], [8, 11])
];

for (let failure of expectedFailures) {
Lint.Test.assertContainsFailure(actualFailures, failure);
}
});

it("disallows functions with parameter type 'any'", () => {
const expectedFailure = createFailure([3, 17], [3, 20]);
Lint.Test.assertContainsFailure(actualFailures, expectedFailure);
});

it("disallows functions with return type 'any'", () => {
const expectedFailure = createFailure([3, 24], [3, 27]);
Lint.Test.assertContainsFailure(actualFailures, expectedFailure);
});

it("catches destructuring bindings with member types of 'any'", () => {
const expectedFailure = createFailure([10, 23], [10, 26]);
Lint.Test.assertContainsFailure(actualFailures, expectedFailure);
});

it("finds the expected number of errors", () => {
assert.equal(actualFailures.length, 6);
});

});

0 comments on commit 7f2dd84

Please sign in to comment.