Re: Why beforeEach doesn't work but this.setupComponent does?

33 views
Skip to first unread message

Gabriel Pugliese

unread,
Dec 16, 2014, 11:13:49 AM12/16/14
to Bogdan Begovic, twitter...@googlegroups.com

Probably because of wrong scope/context of "this"? Have you tried removing the describe context leaving the beforeEach inside the describeComponent context? (Complete shot in the dark)


On Tue, Dec 16, 2014, 07:50 Bogdan Begovic <bogdan...@gmail.com> wrote:
Hi everyone. I am having a really strange problem with one of my tests. I am trying to setupComponent before every it but it doesn't work, but when I just add setupComponent in every it, it works as expected. Maybe the problem is not with neither of them, maybe I am misusing the framework, so I need someones help just to look at the code and tell me if I am doing something wrong, or should I raise a bug.

You can remove beforeEach and everything will work, but if you remove this.setupComponent from it, the test will fail).

/**
 * Created by Bogdan.Begovic on 10/22/2014.
 */

/* global
 beforeEach,
 describe,
 describeComponent,
 expect,
 it,
 setupComponent,
 spyOnEvent,
 spyOn
 */

define([], function () {
        'use strict';
        var setupData = {
            someAttr:true;
        };
        var testData1 = {url: 'test url 1'};
        var testData2 = {url: 'test url 1', testEvent: 'test event 1'};

        var mockConfigurationData = {
            config: {}
        };

        describeComponent('components/data/dataConfiguration', function (   ) {

            describe('initialization -', function () {

                beforeEach(function () {
                    this.setupComponent(setupData);
                });

                it('requesting configuration data', function () {
                    spyOnEvent(document, 'dataConfigurationEvent');
                    this.setupComponent(setupData);
                    expect('dataConfigurationEvent').toHaveBeenTriggeredOnAndWith(document, testData2);
                });
            });

            describe('component ', function () {

                beforeEach(function () {
                    this.setupComponent(setupData);
                });

                it('configuration received', function () {
                    spyOnEvent(document, 'configReady');
                    this.setupComponent(setupData);
                    this.component.trigger('configReceived', mockConfigurationData);
                    expect('configReady').toHaveBeenTriggeredOn(document);
                });

                it('initialized and ready', function () {
                    spyOnEvent(document, 'configReady');
                    this.setupComponent(setupData);
                    this.component.trigger('componentReadyForConfig');
                    expect('configReady').toHaveBeenTriggeredOn(document);
                });
            });

        });
    }
);

Reply all
Reply to author
Forward
0 new messages