Skip to content

test suite #2

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

Open
dherman opened this issue Dec 17, 2011 · 6 comments · May be fixed by #29
Open

test suite #2

dherman opened this issue Dec 17, 2011 · 6 comments · May be fixed by #29

Comments

@dherman
Copy link
Contributor

dherman commented Dec 17, 2011

Need to choose a testing framework and set up a test suite.

@dherman
Copy link
Contributor Author

dherman commented Dec 22, 2011

@juandopazo
Copy link

I wrote some tests using Mocha (see juandopazo@213ada3), but the issue is that since Task catches errors in the generator function there is no clear way to get Mocha to show the correct assertion failures.

Would you be interested in using YUI Test? It uses a resume() function for asynchronous tests that creates a new context to catch errors. Here's an example test:

'task should retrieve a promise\'s value': function () {
    var test = this,
        expected = 'hello world';

    spawn(function () {
        var actual = yield Promise.resolve(expected);
        test.resume(function () {
            Assert.areSame(expected, actual);
        });
    });
    test.wait();
}

@juandopazo
Copy link

Tests using YUI: juandopazo@bc26447.

Another option could be Jasmine. Jasmine tests look very similar to Mocha, but they also provide their own context for assertions through a runs function. It ends up being a lot more code though. See:

it('task should retrieve a promise\'s value': function () {
  var done = false;
  var someString = 'hello world';
  var value;

  runs(function () {
    spawn(function () {
      value = yield Promise.resolve(someString);
      done = true;
    });
  });

  waitsFor(function () {
    return done == true;
  });

  runs(function () {
    expect(value).to.eql(someString);
  });
});

@mbulman
Copy link

mbulman commented Jun 5, 2013

Fwiw, using doh (dojo's test harness) deferreds, the above test would look something like:

function testReturnValue() {
    var expected = "hello world",
        deferred = new doh.Deferred();

    spawn(deferred.getTestCallback(function() {
        var actual = yield Promise.resolve(expected);
        doh.assertEqual(expected, actual);
    }));

    return deferred;
}

Disclaimer: I just happened to be following this thread, and haven't tested the above code at all.

@juandopazo
Copy link

The problem with that version is that spawn expects a generator and getTestCallback returns a callback.

@mbulman
Copy link

mbulman commented Jun 6, 2013

Oh right. Then without the convenience of getTestCallback, it would look something like:

function testReturnValue() {
    var expected = "hello world",
        deferred = new doh.Deferred();

    spawn(function() {
        try {
            var actual = yield Promise.resolve(expected);
            doh.assertEqual(expected, actual);
            deferred.callback(true);
        } catch (e) {
            deferred.errback(e);
        }
    }));

    return deferred;
}

@juandopazo juandopazo linked a pull request Jun 6, 2013 that will close this issue
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 a pull request may close this issue.

3 participants