Skip to content

Commit

Permalink
Add more tests for the <no-any> rule
Browse files Browse the repository at this point in the history
  • Loading branch information
leeavital committed Jun 23, 2015
1 parent 3b3c56c commit 21d1ec5
Show file tree
Hide file tree
Showing 3 changed files with 39 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
33 changes: 29 additions & 4 deletions test/rules/noAnyRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,39 @@
*/

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'", () => {
let 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'", () => {
let expectedFailure = createFailure([3, 17], [3, 20]);
Lint.Test.assertContainsFailure(actualFailures, expectedFailure);
});

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

it("catches destructuring bindings with member types of 'any'", () => {
let 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 21d1ec5

Please sign in to comment.