Skip to content

Commit 5cd971d

Browse files
committed
Add tests for some internal functions
These tests uncover some issues that need to be looked over.
1 parent ed9daee commit 5cd971d

File tree

3 files changed

+101
-2
lines changed

3 files changed

+101
-2
lines changed

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ gulp.task('test', function(cb) {
1818
.pipe(istanbul()) // Covering files
1919
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
2020
.on('finish', function() {
21-
gulp.src(['test/*.js'])
21+
gulp.src(['test/**/*.js'])
2222
.pipe(mocha())
2323
.pipe(istanbul.writeReports()) // Creating the reports after tests runned
2424
.on('end', cb);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
},
1515
"homepage": "https://github.com/Gillespie59/eslint-plugin-angularjs",
1616
"devDependencies": {
17-
"chai": "^3.2.0",
17+
"chai": "^3.3.0",
1818
"coveralls": "^2.11.4",
1919
"eslint": "^1.3.1",
20+
"espree": "^2.2.5",
2021
"gulp": "^3.9.0",
2122
"gulp-eslint": "^1.0.0",
2223
"gulp-istanbul": "^0.10.0",

test/utils/utils.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
'use strict';
2+
3+
/* eslint-env mocha */
4+
/* eslint-disable no-unused-expressions */
5+
6+
var espree = require('espree');
7+
var expect = require('chai').expect;
8+
9+
var utils = require('../../rules/utils/utils');
10+
11+
12+
describe('convertPrefixToRegex', function() {
13+
it('should not handle non-string objects', function() {
14+
var obj = {};
15+
expect(utils.convertPrefixToRegex(obj) === obj).to.be.true;
16+
});
17+
18+
xit('should not convert a string ending and starting with a / to a Regex', function() {
19+
expect(utils.convertPrefixToRegex('/app/'.source)).to.equal('app.*');
20+
});
21+
22+
it('should not convert a regulat string a Regex', function() {
23+
expect(utils.convertPrefixToRegex('app').source).to.equal('app.*');
24+
});
25+
});
26+
27+
describe('convertStringToRegex', function() {
28+
xit('should not convert a string ending and starting with a / to a Regex', function() {
29+
expect(utils.convertStringToRegex('/app/'.source)).to.equal('app');
30+
});
31+
32+
it('should not convert a regulat string a Regex', function() {
33+
expect(utils.convertStringToRegex('app').source).to.equal('app');
34+
});
35+
});
36+
37+
describe('isAngularControllerDeclaration', function() {
38+
it('should return true if the function call chained from a module definition declares a controller', function() {
39+
var ast = espree.parse('angular.module("", []).controller("", function() {});');
40+
expect(utils.isAngularControllerDeclaration(ast.body[0].expression)).to.be.true;
41+
});
42+
43+
it('should return true if the function call chained from a module getter declares a controller', function() {
44+
var ast = espree.parse('angular.module("").controller("", function() {});');
45+
expect(utils.isAngularControllerDeclaration(ast.body[0].expression)).to.be.true;
46+
});
47+
48+
xit('should return false if a controller function from some variable is called', function() {
49+
var ast = espree.parse('app.controller("", function() {});');
50+
expect(utils.isAngularControllerDeclaration(ast.body[0].expression)).to.be.false;
51+
});
52+
53+
it('should return true if a referenced angular module declares a controller', function() {
54+
var ast = espree.parse('var app = angular.module("");app.controller("", function() {});');
55+
expect(utils.isAngularControllerDeclaration(ast.body[1].expression)).to.be.true;
56+
});
57+
58+
it('should return false if too few arguments are passed', function() {
59+
var ast = espree.parse('angular.module("").controller("");');
60+
expect(utils.isAngularControllerDeclaration(ast.body[0].expression)).to.be.false;
61+
});
62+
});
63+
64+
describe('isAngularModuleDeclaration', function() {
65+
it('should return true for an Angular module declaration', function() {
66+
var ast = espree.parse('angular.module("", []);');
67+
expect(utils.isAngularModuleDeclaration(ast.body[0].expression)).to.be.true;
68+
});
69+
70+
it('should return false for an Angular module getter', function() {
71+
var ast = espree.parse('angular.module("");');
72+
expect(utils.isAngularModuleDeclaration(ast.body[0].expression)).to.be.false;
73+
});
74+
});
75+
76+
describe('isAngularModuleGetter', function() {
77+
xit('should return false for an Angular module declaration', function() {
78+
var ast = espree.parse('angular.module("", []);');
79+
expect(utils.isAngularModuleGetter(ast.body[0].expression)).to.be.false;
80+
});
81+
82+
it('should return true for an Angular module getter', function() {
83+
var ast = espree.parse('angular.module("");');
84+
expect(utils.isAngularModuleGetter(ast.body[0].expression)).to.be.true;
85+
});
86+
});
87+
88+
describe('isAngularRunSection', function() {
89+
xit('should return true if the call defines a run function', function() {
90+
var ast = espree.parse('angular.module("").run(function() {});');
91+
expect(utils.isAngularRunSection(ast.body[0].expression)).to.be.true;
92+
});
93+
94+
xit('should return false is a run is called on a random object', function() {
95+
var ast = espree.parse('app.run();');
96+
expect(utils.isAngularRunSection(ast.body[0].expression)).to.be.false;
97+
});
98+
});

0 commit comments

Comments
 (0)