<commit_before>import {Mock} from '../lib/mock';
import {It} from '../lib/expected-expressions/expression-predicates';
import {ExpectedNamedMethodExpression} from '../lib/expected-expressions/expected-expressions';
import {Times} from '../lib/times';
import {MockBehavior} from '../lib/interceptor-callbacks/interceptor-callbacks';

interface ITestObject {
    method(arg: number): string;
}

describe('Mock: Named method', () => {


    it('Returns value with a simple setup', () => {
        const value = 'value';
        const object = new Mock<ITestObject>()
            .setup(instance => instance.method(1))
            .returns(value)
            .object();

        const actual = object.method(1);

        expect(actual).toBe(value);
    });


    //todo: doesn't work since there is no way to make out a property access and function call
    xit('Returns value with a predicated setup', () => {
        const value = 'value';

        const object = new Mock<ITestObject>()
            .setup(instance => It.Is((expression: ExpectedNamedMethodExpression) => expression.name === 'method' && expression.arguments[0] === 1))
            .returns(value)
            .object();

        const actual = object.method(1);

        expect(actual).toBe(value);
    });

    it('Throws TypeError exception when call an unset method in strict mode', () => {
        const value = 'value';
        const object = new Mock<ITestObject>()
            .object();

        expect(() => object.method(1)).toThrow(jasmine.any(TypeError));
    });

    it('Returns undefined when call an unset method in loose mode', () => {
        const value = 'value';
        const mock = new Mock<ITestObject>()
            .setBehaviorStrategy(MockBehavior.Loose);
<commit_msg>unit test ’Returns value with a predicated setup' has been enabled<commit_after>import {Mock} from '../lib/mock';
import {It} from '../lib/expected-expressions/expression-predicates';
import {ExpectedNamedMethodExpression} from '../lib/expected-expressions/expected-expressions';
import {Times} from '../lib/times';
import {MockBehavior} from '../lib/interceptor-callbacks/interceptor-callbacks';

interface ITestObject {
    method(arg: number): string;
}

describe('Mock: Named method', () => {


    it('Returns value with a simple setup', () => {
        const value = 'value';
        const object = new Mock<ITestObject>()
            .setup(instance => instance.method(1))
            .returns(value)
            .object();

        const actual = object.method(1);

        expect(actual).toBe(value);
    });


    //todo: it will work only in Loose mode
    it('Returns value with a predicated setup', () => {
        const value = 'value';

        const object = new Mock<ITestObject>()
            .setBehaviorStrategy(MockBehavior.Loose)
            .setup(instance => It.Is((expression: ExpectedNamedMethodExpression) => expression.name === 'method' && expression.arguments[0] === 1))
            .returns(value)
            .object();

        const actual = object.method(1);

        expect(actual).toBe(value);
    });

    it('Throws TypeError exception when call an unset method in strict mode', () => {
        const value = 'value';
        const object = new Mock<ITestObject>()
            .object();

        expect(() => object.method(1)).toThrow(jasmine.any(TypeError));
    });

    it('Returns undefined when call an unset method in loose mode', () => {
        const value = 'value';
        const mock = new Mock<ITestObject>()
            .setBehaviorStrategy(MockBehavior.Loose);

{'fraction_non_alphanumeric': 0.14409625069949636, 'fraction_numerical': 0.003357582540570789, 'mean_word_length': 2.743455497382199, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, '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': '976800', 'n_tokens_mistral': 972, 'n_tokens_neox': 940, 'n_words': 264}