<commit_before>'use strict';

var chai = require('chai'),
    chaiAsPromised = require('chai-as-promised'),
    sinon = require('sinon');

if (!global.Promise) {
    global.Promise = require('promise-polyfill');
}
chai.use(chaiAsPromised);
chai.should();

var aplus = require('../../lib/aplus');

describe('aplus.forever()', function () {
    it('should loop until inner promise rejects', function () {
        var target = Math.ceil(Math.random() * 20) + 10,
            count = 0,
            expected = new Error('hi!');

        function task() {
            count++;
            if (count > target) {
                throw expected;
            }
            return Promise.resolve(count);
        }
        return aplus.forever(task).catch(function (err) {
            err.should.equal(expected);
        });
    });
    it('should termintate loop when exception is thrown', function () {
        var expected = new Error('hi!');

        function task() {
            throw expected;
        }
        return aplus.forever(task).catch(function (err) {
            err.should.equal(expected);
        });
    });
    it('should termintate loop when task rejects', function () {
        var expected = new Error('hi!');

        function task() {
            return Promise.reject(expected);
        }
        return aplus.forever(task).catch(function (err) {
            err.should.equal(expected);
        });
    });
})<commit_msg>fix lint error<commit_after>'use strict';

var chai = require('chai'),
    chaiAsPromised = require('chai-as-promised');
    
if (!global.Promise) {
    global.Promise = require('promise-polyfill');
}
chai.use(chaiAsPromised);
chai.should();

var aplus = require('../../lib/aplus');

describe('aplus.forever()', function () {
    it('should loop until inner promise rejects', function () {
        var target = Math.ceil(Math.random() * 20) + 10,
            count = 0,
            expected = new Error('hi!');

        function task() {
            count++;
            if (count > target) {
                throw expected;
            }
            return Promise.resolve(count);
        }
        return aplus.forever(task).catch(function (err) {
            err.should.equal(expected);
        });
    });
    it('should termintate loop when exception is thrown', function () {
        var expected = new Error('hi!');

        function task() {
            throw expected;
        }
        return aplus.forever(task).catch(function (err) {
            err.should.equal(expected);
        });
    });
    it('should termintate loop when task rejects', function () {
        var expected = new Error('hi!');

        function task() {
            return Promise.reject(expected);
        }
        return aplus.forever(task).catch(function (err) {
            err.should.equal(expected);
        });
    });
});
{'fraction_non_alphanumeric': 0.14821303433777155, 'fraction_numerical': 0.00350385423966363, 'mean_word_length': 2.024364406779661, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6928179', 'n_tokens_mistral': 823, 'n_tokens_neox': 794, 'n_words': 180}