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

Proposal: multiple async conditions #29

Open
mcbain opened this issue Dec 29, 2014 · 2 comments
Open

Proposal: multiple async conditions #29

mcbain opened this issue Dec 29, 2014 · 2 comments

Comments

@mcbain
Copy link

mcbain commented Dec 29, 2014

With a little modified version of the pollUntil function multiple async conditions using normal expectations could be supported. Since those expect() call always throw an informative assertion-error, it could be used also as more helpful test-error message.

            var i = 0;

            Meteor.setInterval(function () {
                i++;
            }, 100);

            until(
                waitFor,
                function () {
                    expect(i).to.equal(10);
                });

            until(
                waitFor,
                function () {
                    expect(i).to.equal('A');
                });

This example has two conditions, where the last one will never be true and result in a timeout with

   timeout after 4800ms waiting for: expected 48 to equal 'A'

One problem is still the "global-test-timeout", which after 5s terminates the test with Async batch timed out. The detailed error messages are only visible when they timeout little earlier.

Even more better to read could be

  waitFor.condition(function () {
                    expect(i).to.equal(10);
                })

This would need some changes in the ExpectationManager.

Here is the until function.

    until = function (expect, condition, timeout) {
        var step = 100;
        var start = (new Date()).valueOf();
        timeout = timeout || 4800;

        var lastError;

        var complete = expect(function (error) {
            if (error) {
                throw new Error('timeout after ' + timeout + 'ms waiting for: ' + lastError.message);
            }
        });

        var helper = function () {
            try {
                condition();
                complete();
                return;
            }
            catch (e) {
                lastError = e;
            }

            if (start + timeout < (new Date()).valueOf()) {
                complete(true);
                return;
            }
            Meteor.setTimeout(helper, step);
        };
        helper();
    };
@rbabayoff
Copy link
Member

Hey,

Munit was at the time something built on top of meteor's tinytest and due to tinytest's immaturity, compared to mocha and jasmine, is missing a lot of features. We are actually working on a mocha for packages solution, so we don't invest anymore time on trying and improve munit.

@mcbain
Copy link
Author

mcbain commented Apr 28, 2015

@rbabayoff I just browsed your repos, but the meteor-mocha had the last change half year ago. Saw that you forked mocha repo directly. Its currently possible to use it for package tests?

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

No branches or pull requests

2 participants