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 asjQuery.get(buster.env.contextPath + "/some/cookies.json")
;
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?