Reputation: 57
my code is below, can someone go into jslint and paste my code and show me why my errors are occurring and fixes. for example it says 'describe' is used before it is defined, but in the pages on the angularjs website they do not show any definition. another error is "Unexpected character ''." on line 2 character 42. there is also false as there is no missing space.
describe('forgotPasswordCtrl', function () {
beforeEach(module('forgotPasswordApp'));
var $controller;
var returnMsg = 'Forgot password response message';
beforeEach(inject(function(_$controller_){
$controller = _$controller_;
}));
describe('$scope.finish', function(){
it('returns a -forgot password response- message', function(){
var $scope = {};
var controller = $controller('forgotPasswordCtrl', { $scope: $scope });
$scope.finish();
expect($scope.globalError).toEqual(returnMsg);
});
});
describe('$scope.cancel', function(){
it('assigns a url depending on a customer match happens', function(){
var $scope = {};
var controller = $controller('forgotPasswordCtrl', { $scope: $scope });
$scope.cancel();
expect(window.location.assign).toEqual("/web/tfgm_customer");
});
});
Upvotes: 0
Views: 457
Reputation: 17473
Wow. Okay, so you're not always going to be able to get libraries to lint correctly. If this code is supposed to work in context, then there's a lot of spaghetti going on.
Here's my best guess with what you've given. Let me know what I got wrong.
Notes: You need some /*jslint ... */
directives at the top of your file.
sloppy:true
: Allows you to leave off 'use strict'white:true
: Allows indiscriminate whitespacenomen:true
: Allows underscores (_
) at start and end of variable names.browser:true
: Here, allows the use of window
.Note also the /*global ... */
directive, where you can put all these functions that, for some strange reason, don't live in a namespace.
Here we go:
/*jslint sloppy:true, white:true, nomen:true, browser:true */
/*global describe, module, beforeEach, inject, it, expect */
// You have some bad scoping below. I *think* you expect
// $controller, controller, & returnMsg to exist in full
// script scope.
var returnMsg, $controller = null, controller = null;
describe('forgotPasswordCtrl', function () {
beforeEach(module('forgotPasswordApp'));
returnMsg = 'Forgot password response message';
beforeEach(inject(function(_$controller_){
// You're never doing anything with this.
// JSLint wants to know why not.
$controller = _$controller_;
}));
});
describe('$scope.finish', function(){
it('returns a -forgot password response- message', function(){
var $scope = {};
controller = $controller('forgotPasswordCtrl', { $scope: $scope });
$scope.finish();
expect($scope.globalError).toEqual(returnMsg);
});
});
describe('$scope.cancel', function(){
it('assigns a url depending on a customer match happens', function(){
var $scope = {};
controller = $controller('forgotPasswordCtrl', { $scope: $scope });
$scope.cancel();
expect(window.location.assign).toEqual("/web/tfgm_customer");
});
});
$controller.usedSomehow(); // to make JSLint happy. Please use.
controller.usedSomehowAsWell(); // to make JSLint happy. Please use.
Honestly, there's so much wacky going on here, I'm not sure what to make of it. I think you need to give us a better description of what you think you're doing (it's obviously (?) unit testing something), but stuff like...
var $scope = {};
controller = $controller('forgotPasswordCtrl', { $scope: $scope });
Doesn't make much sense. $scope is an object that you pass to a property also called $scope in an anon object passed to $controller? Why? Why not...
controller = $controller('forgotPasswordCtrl', { $scope: {} });
... ? My guess is that you've got lots of stuff happening in different scopes around this code that you need to pin down before you can really start linting your code.
That is, does it work as is?
Edit after comment:
If you were getting something like this...
Unexpected character '(space)'.
beforeEach(module('forgotPasswordApp'));
... that's because you didn't have white:true
in a JSLint directive. Check the JSLint instructions page for more about all these options, which says this about white
:
true
if strict whitespace rules should be ignored.
The error you're seeing is sort of misleading. If you have any trailing spaces at the end of your line, that error could be thrown.
Upvotes: 1
Reputation: 6768
I gave a look at what JSHint said about it. JSHint is less strict than JSLint and easier to read but has less features.
You're missing a parenthesis and a bracket. It says "undefined" about a lot of things because you didn't define a lot of things, starting with the "describe" function. You're using global functions and variables which haven't been declared. If that's added by another script / library, jslint or jshint aren't going to guess it for you. If you want it to stop complaining, just add a line at the top which says var describe, module, beforeEach, inject, it, expect;
Upvotes: 0