Skip to content

test suite #2

Open
Open

Description

@dherman

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

Activity

  1. dherman commented on Dec 22, 2011

    @dherman
    ContributorAuthor
  2. juandopazo commented on Jun 2, 2013

    @juandopazo

    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();
    }
  3. juandopazo commented on Jun 4, 2013

    @juandopazo

    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);
      });
    });
  4. mbulman commented on Jun 5, 2013

    @mbulman

    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.

  5. juandopazo commented on Jun 5, 2013

    @juandopazo

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

  6. mbulman commented on Jun 6, 2013

    @mbulman

    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;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions