Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests stronger #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Make tests stronger #4

wants to merge 1 commit into from

Conversation

SuperMegaGiperProger
Copy link

The tests of fromJSON function uses Rectangle function like this:

it.optional('fromJSON should return the object of specified type from JSON representation', function () {
        var MockType = function(a,b,c) {
            this.a = a;
            this.b = b;
            this.c = c;
        };

        [
            {
                proto: tasks.Rectangle.prototype,
                json: '{ "width":10, "height":20 }',
                expected: new tasks.Rectangle(10, 20)
            },{
                proto: MockType.prototype,
                json: '{ "a":10, "b":20, "c":30 }',
                expected: new MockType(10,20,30)
            }
        ].forEach(data => {
            var actual = tasks.fromJSON(data.proto, data.json);
            assert.deepEqual(
                actual,
                data.expected,
                'fromJson method shoud restore all properties from json'
            );
            assert.equal(
                actual.__proto__,
                data.expected.__proto__,
                'fromJson method shoud restore type from prototype argument'
            );
        });
    });

These tests expect that Rectangle prototype has the method getArea, but Rectangle can be implemented in other way and Rectangle tests allow to do it. For example, tests allow to implement Rectangle like this:

function Rectangle(width, height) {
    return {width: width, height: height, getArea: () => width * height}
}

In this example Rectangle prototype doesn't have getArea method. So, this case should be checked in tests.

Why is it important? If you implement Rectangle in wrong way, you will get message that fromJSON function works incorrect, even if it is implemented in right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant