describe "CMS.Models.Module", -> it "set the correct URL", -> expect(new CMS.Models.Module().url).toEqual("/save_item") it "set the correct default", -> expect(new CMS.Models.Module().defaults).toEqual({data: ""}) describe "loadModule", -> describe "when the module exists", -> beforeEach -> @fakeModule = jasmine.createSpy("fakeModuleObject") window.FakeModule = jasmine.createSpy("FakeModule").andReturn(@fakeModule) @module = new CMS.Models.Module(type: "FakeModule") @stubDiv = $('
') @stubElement = $('') @stubElement.data('type', "FakeModule") @stubDiv.append(@stubElement) @module.loadModule(@stubDiv) afterEach -> window.FakeModule = undefined it "initialize the module", -> expect(window.FakeModule).toHaveBeenCalled() # Need to compare underlying nodes, because jquery selectors # aren't equal even when they point to the same node. # http://stackoverflow.com/questions/9505437/how-to-test-jquery-with-jasmine-for-element-id-if-used-as-this expectedNode = @stubElement[0] actualNode = window.FakeModule.mostRecentCall.args[0][0] expect(actualNode).toEqual(expectedNode) expect(@module.module).toEqual(@fakeModule) describe "when the module does not exists", -> beforeEach -> @previousConsole = window.console window.console = jasmine.createSpyObj("fakeConsole", ["error"]) @module = new CMS.Models.Module(type: "HTML") @module.loadModule($("