3

I'm looking for a good example that shows how to use busterJS's resource property in the buster.js config file to include a .json file in a test case.

From the documentation:

resources

Additional resources that will be made available for test runs, but not explicitly loaded. Value is an array of resources. Resources are served from a context path on the server. To request a resource in your test runs, you need to scope resource paths with buster.env.contextPath. The resource /some/cookies.json can be requested as jQuery.get(buster.env.contextPath + "/some/cookies.json");

It also states:

A "resource" is something exposed on the server when you run browser tests using buster-server and buster-test. Exposing the resource /something.json allows you to request it in your tests using e.g. jQuery.ajax({ url: "something.json" });.

And here's the example they give:

    config["Browser build tests"] = {
    environment: "browser",
    libs: ["lib/**.js"],
    resources: [
        "src/**.js",
        { path: "/mylib.min.js",
          combine: ["src/base.js", "src/dom.js"] }
    ],
    sources: ["/mylib.min.js"],
    tests: ["test/**.js"]
};

However, they don't give a solid example of using the JSON file in a unit test. When I've tried following their examples, jQuery throws a 404 when I try doing jQuery.ajax({ url: "[my-file-name-here]" }).

Has anyone ever successfully used this feature?

Levi Hackwith
  • 9,232
  • 18
  • 64
  • 115

1 Answers1

1

This is how it's supposed to work: https://gist.github.com/4554427 But I'm seeing weird responseText with this, so I need to look into why that happens...

Christian Johansen
  • 1,861
  • 1
  • 16
  • 22
  • Would you mind also elaborating on when it's appropriate to use a resource in your unit tests? Or what problem are they meant to solve? – Levi Hackwith Jan 17 '13 at 14:47