[Framework] Initial spec for bundle loader

Add first test case for bundle loader, WTD-518.
This commit is contained in:
Victor Woeltjen 2014-11-06 14:28:22 -08:00
parent dac05d7841
commit 8e1eb2f22f
2 changed files with 54 additions and 5 deletions

View File

@ -55,7 +55,7 @@ define(
bootstrapper.bootstrap(mockApp);
});
// The tests.
it("waits for the provided document element to be ready", function () {

View File

@ -1,14 +1,63 @@
/*global define,Promise,describe,it,expect,beforeEach*/
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,runs,jasmine*/
/**
* BundleLoaderSpec. Created by vwoeltje on 11/6/14.
*/
define(
[],
function () {
["../../src/load/BundleLoader"],
function (BundleLoader) {
"use strict";
describe("", function () {
describe("The bundle loader", function () {
var loader,
mockCallback,
mockHttp,
mockLog,
testBundles;
// Used to wait for then-chain resolution;
// native promises may not resolve synchronously,
// even when values are immediately available.
function mockCallbackResolved() {
return mockCallback.calls.length > 0;
}
beforeEach(function () {
testBundles = [
{
},
{
}
];
mockCallback = jasmine.createSpy("callback");
mockHttp = jasmine.createSpyObj("$http", ["get"]);
mockLog = jasmine.createSpyObj("$log", ["error", "warn", "info", "debug"]);
loader = new BundleLoader(mockHttp, mockLog);
});
it("accepts a JSON file name and loads all bundles", function () {
// Set up; just return an empty set of bundles for this test
mockHttp.get.andReturn(Promise.resolve({data: []}));
// Call load bundles
loader.loadBundles("test-filename.json").then(mockCallback);
waitsFor(mockCallbackResolved, "then-chain resolution", 100);
runs(function () {
// Should have loaded the file via $http
expect(mockHttp.get).toHaveBeenCalledWith("test-filename.json");
// Should have gotten an empty bundle list
expect(mockCallback).toHaveBeenCalledWith([]);
});
});
});
}