<commit_before>﻿/// <reference path="../src/promise.d.ts" />
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/should/should.d.ts" />
/// <reference path="../typings/sinon/sinon.d.ts" />

import abstract = require("src/promise/abstract");
import Promise = require("src/promise/class");
import commonHelpers = require("./helpers/common");

describe("Promise Constructor", () => {
    var initializePromiseStub: SinonStub;
    beforeEach(() => { initializePromiseStub = sinon.stub(abstract, "initializePromise"); });
    afterEach(() => { initializePromiseStub.restore(); });

    it("should throws a TypeError if given argument is not a Function", () => {
        var P: any = Promise;
        (() => { new P({}); }).should.throw(TypeError);
        (() => { new P(null); }).should.throw(TypeError);
        (() => { new P("test"); }).should.throw(TypeError);
    });

    it("should throws a TypeError if not called using new keyword", () => {
        var P: any = Promise;
         (() => { P(null); }).should.throw(TypeError);
    });

    it("should call InitializePromise Abstract Operations with itself and executor method", () => {
        console.log(Promise);
        var executor = commonHelpers.noop(),
            promise = new Promise(executor);

        sinon.assert.calledOnce(initializePromiseStub);
        sinon.assert.calledWithExactly(initializePromiseStub, promise, executor);<commit_msg>Remove console.log in constructor tests<commit_after>﻿/// <reference path="../src/promise.d.ts" />
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/should/should.d.ts" />
/// <reference path="../typings/sinon/sinon.d.ts" />

import abstract = require("src/promise/abstract");
import Promise = require("src/promise/class");
import commonHelpers = require("./helpers/common");

describe("Promise Constructor", () => {
    var initializePromiseStub: SinonStub;
    beforeEach(() => { initializePromiseStub = sinon.stub(abstract, "initializePromise"); });
    afterEach(() => { initializePromiseStub.restore(); });

    it("should throws a TypeError if given argument is not a Function", () => {
        var P: any = Promise;
        (() => { new P({}); }).should.throw(TypeError);
        (() => { new P(null); }).should.throw(TypeError);
        (() => { new P("test"); }).should.throw(TypeError);
    });

    it("should throws a TypeError if not called using new keyword", () => {
        var P: any = Promise;
         (() => { P(null); }).should.throw(TypeError);
    });

    it("should call InitializePromise Abstract Operations with itself and executor method", () => {
        var executor = commonHelpers.noop(),
            promise = new Promise(executor);

        sinon.assert.calledOnce(initializePromiseStub);
        sinon.assert.calledWithExactly(initializePromiseStub, promise, executor);
{'fraction_non_alphanumeric': 0.1828591256072172, 'fraction_numerical': 0.0, 'mean_word_length': 3.3549848942598186, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, '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': '1737891', 'n_tokens_mistral': 817, 'n_tokens_neox': 812, 'n_words': 182}