Last active
January 1, 2018 20:38
-
-
Save Integralist/5772010 to your computer and use it in GitHub Desktop.
Revisions
-
Integralist revised this gist
Jul 16, 2013 . 2 changed files with 21 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ var mocks = { resizeCalled: false, @@ -13,6 +12,14 @@ var mocks = { } }, history: { back: function(){} }, location: { replace: function(){} }, resizeTo: function(width, height) { this.document.documentElement = { clientWidth: width, @@ -58,4 +65,17 @@ it('should only publish `device` event when device type changes', function(){ fakeWindow.resizeTo(320, 480); mocks.fireResizeEvent(); }); it('should take the user back to the previous page in their history', function(){ var fakeWindow = mocks.createFakeWindow(), fakeWindowHistoryBackSpy = sinon.spy(fakeWindow.history, 'back'), fakeWindowLocationReplaceSpy = sinon.spy(fakeWindow.location, 'replace'); pictureViewer.init(fakeWindow); $('.picture-viewer__button--back').trigger('click'); expect(fakeWindowHistoryBackSpy).toHaveBeenCalledOnce(); expect(fakeWindowLocationReplaceSpy).toHaveBeenCalledOnce(); }); File renamed without changes. -
Integralist revised this gist
Jun 13, 2013 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ var mocks = { resizeCalled: false, -
Integralist created this gist
Jun 13, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ var mocks = { resizeCalled: false, createFakeWindow: function(width, height) { var module = this; return { document: { documentElement: { clientWidth: width, clientHeight: height } }, resizeTo: function(width, height) { this.document.documentElement = { clientWidth: width, clientHeight: height }; } }; }, fireResizeEvent: function() { this.handler(); }, news: { $: function(element) { return { on: function(event, handler) { if (event === 'resize') { mocks.resizeCalled = true; } mocks.handler = handler; } }; } } }; it('should bind to `resize` event on `init`', function(){ var fakeWindow = mocks.createFakeWindow(320, 480); deviceInspector.init(fakeWindow, mocks.news); expect(mocks.resizeCalled).toBeTruthy(); }); it('should only publish `device` event when device type changes', function(){ var fakeWindow = mocks.createFakeWindow(1008, 1024), device = deviceInspector.init(fakeWindow, mocks.news); fakeWindow.resizeTo(960, 1024); mocks.fireResizeEvent(); fakeWindow.resizeTo(320, 480); mocks.fireResizeEvent(); }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ function bindEvents() { news.$(global).on('resize', handleResize); } function init(windowMock, newsMock) { global = windowMock || window; news = newsMock || newsModule; }