private _adapter, ES6 setters and getters

This commit is contained in:
Florent Vilmart
2016-02-22 14:12:51 -05:00
parent 23e55e941e
commit 045caca946
2 changed files with 56 additions and 17 deletions

View File

@@ -15,6 +15,11 @@ describe("AdaptableController", ()=>{
var adapter = new FilesAdapter();
var controller = new FilesController(adapter);
expect(controller.adapter).toBe(adapter);
// make sure _adapter is private
expect(controller._adapter).toBe(undefined);
// Override _adapter is not doing anything
controller._adapter = "Hello";
expect(controller.adapter).toBe(adapter);
done();
});
@@ -26,6 +31,17 @@ describe("AdaptableController", ()=>{
done();
});
it("should fail setting the wrong adapter to the controller", (done) => {
function WrongAdapter() {};
var adapter = new FilesAdapter();
var controller = new FilesController(adapter);
var otherAdapter = new WrongAdapter();
expect(() => {
controller.adapter = otherAdapter;
}).toThrow();
done();
});
it("should fail to instantiate a controller with wrong adapter", (done) => {
function WrongAdapter() {};
var adapter = new WrongAdapter();
@@ -41,4 +57,31 @@ describe("AdaptableController", ()=>{
}).toThrow();
done();
});
it("should accept an object adapter", (done) => {
var adapter = {
createFile: function(config, filename, data) { },
deleteFile: function(config, filename) { },
getFileData: function(config, filename) { },
getFileLocation: function(config, filename) { },
}
expect(() => {
new FilesController(adapter);
}).not.toThrow();
done();
});
it("should accept an object adapter", (done) => {
function AGoodAdapter() {};
AGoodAdapter.prototype.createFile = function(config, filename, data) { };
AGoodAdapter.prototype.deleteFile = function(config, filename) { };
AGoodAdapter.prototype.getFileData = function(config, filename) { };
AGoodAdapter.prototype.getFileLocation = function(config, filename) { };
var adapter = new AGoodAdapter();
expect(() => {
new FilesController(adapter);
}).not.toThrow();
done();
});
});