[API Refactor] Update failing specs

This commit is contained in:
Victor Woeltjen 2016-01-08 12:58:06 -08:00
parent 65c0cc66b6
commit df631ba40e
3 changed files with 26 additions and 18 deletions

View File

@ -30,6 +30,12 @@ define(
var mockScope,
mctForm;
function installController() {
var controllerProperty = mctForm.controller,
Controller = mctForm.controller[1];
return new Controller(mockScope);
}
beforeEach(function () {
mockScope = jasmine.createSpyObj("$scope", [ "$watch" ]);
mockScope.$parent = {};
@ -44,7 +50,7 @@ define(
// mct-form needs to watch for the form by name
// in order to convey changes in $valid, $dirty, etc
// up to the parent scope.
mctForm.controller(mockScope);
installController();
expect(mockScope.$watch).toHaveBeenCalledWith(
"mctForm",
@ -56,7 +62,7 @@ define(
var someState = { someKey: "some value" };
mockScope.name = "someName";
mctForm.controller(mockScope);
installController();
mockScope.$watch.mostRecentCall.args[1](someState);
@ -65,7 +71,7 @@ define(
it("allows strings to be converted to RegExps", function () {
// This is needed to support ng-pattern in the template
mctForm.controller(mockScope);
installController();
// Should have added getRegExp to the scope,
// to convert strings to regular expressions
@ -78,7 +84,7 @@ define(
regExp;
// Add getRegExp to scope
mctForm.controller(mockScope);
installController();
regExp = mockScope.getRegExp(strRegExp);
// Same object instance each time...
@ -91,7 +97,7 @@ define(
var regExp = /^\d+[a-d]$/;
// Add getRegExp to scope
mctForm.controller(mockScope);
installController();
// Should have added getRegExp to the scope,
// to convert strings to regular expressions
@ -100,7 +106,7 @@ define(
it("passes a non-whitespace regexp when no pattern is defined", function () {
// If no pattern is supplied, ng-pattern should match anything
mctForm.controller(mockScope);
installController();
expect(mockScope.getRegExp()).toEqual(/\S/);
expect(mockScope.getRegExp(undefined)).toEqual(/\S/);
});

View File

@ -37,7 +37,6 @@ define(
describe("The logging level handler", function () {
var mockLog,
mockApp,
mockProvide,
mockDelegate,
mockMethods;
@ -61,8 +60,7 @@ define(
beforeEach(function () {
mockMethods = jasmine.createSpyObj("levels", LOG_METHODS);
mockLog = jasmine.createSpyObj('$log', LOG_METHODS);
mockApp = jasmine.createSpyObj('app', ['config']);
mockProvide = jasmine.createSpyObj('$provide', ['decorator']);
mockApp = jasmine.createSpyObj('app', ['config', 'decorator']);
mockDelegate = jasmine.createSpyObj('$delegate', LOG_METHODS);
LOG_METHODS.forEach(function (m) {
@ -70,14 +68,11 @@ define(
mockDelegate[m].andCallFake(mockMethods[m]);
});
mockApp.config.andCallFake(function (callback) {
callback(mockProvide);
});
mockProvide.decorator.andCallFake(function (key, callback) {
// Only $log should be configured in any case
expect(key).toEqual('$log');
callback(mockDelegate);
mockApp.decorator.andCallFake(function (key, decoration) {
// We only expect $log to be decorated
if (key === '$log' && decoration[0] === '$delegate') {
decoration[1](mockDelegate);
}
});
});

View File

@ -34,6 +34,7 @@ define(
mockCallback,
mockHttp,
mockLog,
mockRegistry,
testBundles;
// Used to wait for then-chain resolution;
@ -53,7 +54,13 @@ define(
mockCallback = jasmine.createSpy("callback");
mockHttp = jasmine.createSpyObj("$http", ["get"]);
mockLog = jasmine.createSpyObj("$log", ["error", "warn", "info", "debug"]);
loader = new BundleLoader(mockHttp, mockLog);
mockRegistry = jasmine.createSpyObj(
'legacyRegistry',
[ 'list', 'contains', 'get' ]
);
mockRegistry.list.andReturn([]);
mockRegistry.contains.andReturn(false);
loader = new BundleLoader(mockHttp, mockLog, mockRegistry);
});
it("accepts a JSON file name and loads all bundles", function () {