bebraw / bunit.js

Simple testing lib for JS (MIT)
MIT License
7 stars 2 forks source link

Extra Async Testing for BUnit #3

Closed palodequeso closed 3 years ago

palodequeso commented 11 years ago

Would it be possible to add a more complex async test... perhaps one that actually spoofs the server and does a full ajax request? Just for test completeness sake:

define(function(require) {
    var bunit = require("external/bunit/bunit");
    var assert = require("external/bunit/assert");

    var $ = require("jquery");

    bunit("Request manager", {
        tearDown: function() {
            $(".btn").click();
        },
        asyncTest: function(o, done) {
            var server = sinon.sandbox.useFakeServer();
            server.respondWith("GET", "/test/1", [
                200, { "Content-Type": "application/json" },
                '{"response": "some_response"}'
            ]);

            // call stop(); now if you want, since we named our test using async prefix,
            // that won't be needed
            $.ajax({
                type: "GET",
                url: "/test/1",
                success: function(data) {
                    assert(data.response).equals("some_response");
                    done();
                }
            });
            server.respond();
        }
    });
});
bebraw commented 11 years ago

How does the current solution fail in this case? Kind of missing the point here, my apologies. :)

bebraw commented 3 years ago

Let's close as it has been long enough and bunit is sort of deprecated by now with lots of options available.