I am working on a web app that uses SVG graphics for most of its display and interaction. I would like to use Karma to create unit tests that load an SVG asset, makes sure that certain groups/paths are present, etc.
I haven't found any straightforward answers to how to do this yet, or figured it out on my own yet. I am attempting to get a simple test like this to pass (using mocha & chai):
describe("SimpleDecalRoulette", function() {
it("decal SVG can be loaded", function() {
var decalLoaded = false;
var SVG = Snap.load("/base/app/img/decal.svg", function(fragment) {
decalLoaded = true;
});
expect(decalLoaded).to.be.true;
});
});
Initially, I assumed that including the svg file in the "files" directive of karma.conf.js would suffice:
files: [
{ pattern: 'app/bower_components/lodash/dist/lodash.min.js', watched: false, included: true, served: true },
{ pattern: 'app/bower_components/jquery/dist/jquery.min.js', watched: false, included: true, served: true },
{ pattern: 'app/bower_components/snap.svg/dist/snap.svg-min.js', watched: false, included: true, served: true },
{ pattern: 'app/js/\*\*/\*.js', watched: true, included: true, served: true },
{ pattern: 'app/img/decal.svg', watched: true, included: false, served: true },
{ pattern: 'app/img/assets.svg', watched: true, included: false, served: true },
'tests/\*\*/\*_spec.js'
],
proxies: {
'/app/img/': '/base/app/img/'
}
However, attempting to load the svg files from app/img/decal.svg
or base/app/img/decal.svg
both resulted in 404 errors. I have also tried using the 'proxies' directive, as detailed in this SO answer, but haven't gotten that to work yet either (as seen above).
Is this something that karma can do or is this a use case that should be handled differently? I need to load and interact with SVGs for karma to be useful in writing unit tests for this game.