{"size": 1763, "ext": "js", "max_stars_repo_path": "test/specs/rules/disallow-named-unassigned-functions.js", "max_stars_repo_name": "Alex314Ru/node-jscs", "max_stars_repo_stars_event_min_datetime": "2015-01-01T03:30:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T11:42:48.000Z", "max_issues_repo_path": "test/specs/rules/disallow-named-unassigned-functions.js", "max_issues_repo_name": "Alex314Ru/node-jscs", "max_issues_repo_issues_event_min_datetime": "2015-01-01T00:08:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-20T03:40:58.000Z", "max_forks_repo_path": "test/specs/rules/disallow-named-unassigned-functions.js", "max_forks_repo_name": "Alex314Ru/node-jscs", "max_forks_repo_forks_event_min_datetime": "2015-01-01T19:45:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-24T01:58:52.000Z"}
{"max_stars_count": 3716, "max_issues_count": 1530, "max_forks_count": 637, "avg_line_length": 41.9761904762, "max_line_length": 101, "alphanum_fraction": 0.5916052184}
var Checker = require('../../../lib/checker');
var expect = require('chai').expect;

describe('rules/disallow-named-unassigned-functions', function() {
    var checker;

    beforeEach(function() {
        checker = new Checker();
        checker.registerDefaultRules();
    });

    describe('option value true', function() {
        beforeEach(function() {
            checker.configure({
                disallowNamedUnassignedFunctions: true
            });
        });

        it('should not report on unnamed unassigned function expressions', function() {
            expect(checker.checkString('$("hi").click(function(){});')).to.have.no.errors();
        });

        it('should report on named unassigned function expressions', function() {
            expect(checker.checkString('$("hi").click(function named(){});'))
              .to.have.one.validation.error.from('disallowNamedUnassignedFunctions');
        });

        it('should not report on named function declarations', function() {
            expect(checker.checkString('function named(){};')).to.have.no.errors();
        });

        it('should not report on assigned function expressions', function() {
            expect(checker.checkString('var x = function(){};')).to.have.no.errors();
            expect(checker.checkString('var foo = {bar: function() {}};')).to.have.no.errors();
            expect(checker.checkString('foo.bar = function() {};')).to.have.no.errors();
            expect(checker.checkString('var x = function named(){};')).to.have.no.errors();
            expect(checker.checkString('var foo = {bar: function named() {}};')).to.have.no.errors();
            expect(checker.checkString('foo.bar = function named() {};')).to.have.no.errors();
        });
    });
});
