Strange error when testing mixin in my flight app

28 views
Skip to first unread message

Bogdan Begovic

unread,
Jan 13, 2015, 5:50:55 AM1/13/15
to twitter...@googlegroups.com
I am trying to test a mixin that is shared between two data components in my app. 

This is my mixin, stripped down for simplicity:
define(
    [],
    function () {
        'use strict';

        function withDataCore() {

            this.initializeWidget = function (ev, data) {
                self.trigger('eventName');
                self.off('someOtherEvent');
            };

            this.reinitializeWidget = function (ev, data) {
               //Reinit method ...
            };

        }

        return withDataCore;
    }
);


And this is my test for that mixin: 
define(
    [],
    function () {
        'use strict';
        describeMixin('mixins/core/withDataCore', function () {
            var testData = {
 // Some init data ... 
};

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

            describe('initializeWidget method - ', function () {
                it('test', function () {
                    //given
                    var spy = spyOnEvent(this.component.node, 'eventName');

                    //when
                    this.component.initializeWidget();

                    expect(spy).toHaveBeenTriggeredOn('eventName');
                });
            });

            describe('reinitializeWidget method - ', function () {
                it('test', function () {
                    //given
                    spyOnEvent(this.component.node, 'eventName');

                    //when
                    this.component.reinitializeWidget();
                    //then
                    expect('eventName').toHaveBeenTriggeredOn(this.component.node);
                });
            });
        });
    }
);

When i run the test for only this mixin, everything is ok (using ddescribeMixin), but when i run all the test, including the tests for the components in which the mixin is mixed in, i get this error:

Chrome 39.0.2171 (Windows 8.1) mixins/core/withDataCore initializeWidget method -  test FAILED
timeout: timed out after 5000 msec waiting for something to happen

When i comment out both of these components that are using this mixin and run all of the tests, again, everything is ok.

Does anybody have a clue what is going on here?

I would really appreciate your help.
Sorry for the long post. :)

Gabriel Pugliese

unread,
Jan 13, 2015, 6:11:41 AM1/13/15
to Bogdan Begovic, twitter...@googlegroups.com
I've not tested it but try this:


describe('initializeWidget method - ', function () {
    it('test', function () {
        //given
        var spy = spyOnEvent(this.component.$node, 'eventName');

        //when
        this.component.initializeWidget();

        expect(spy).toHaveBeenTriggeredOn(this.component.$node);
    });
});

Bogdan Begovic

unread,
Jan 13, 2015, 6:17:51 AM1/13/15
to twitter...@googlegroups.com, bogdan...@gmail.com
I have tried it and it still fails when i test everything, but succeeds when i run only test for this mixin. Also, i have moved the methods from mixin test to component tests in which this mixin is mixed in, and everything is ok, so that means that tests are ok, but i have some problem with configuration or something...

Thanks for the quick reply though :)
Reply all
Reply to author
Forward
0 new messages