Created
September 1, 2010 14:14
-
-
Save joecorcoran/560735 to your computer and use it in GitHub Desktop.
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 characters
| var app = $.sammy(function() { | |
| var context = this; | |
| this.get('#/', function() { | |
| this.trigger('myEvent', { h1: 'My app', text: 'world' }); | |
| }); | |
| this.bind('myEvent', function(e, opts) { | |
| $('h1').html(opts.h1); | |
| $('p#text').html(context.url.build('hello', opts.text)); | |
| }); | |
| this.url = { | |
| build: function(key, val) { | |
| return '#/'+key+'/'+val; | |
| } | |
| }; | |
| }); | |
| $(function() { | |
| app.run('#/'); | |
| }); |
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 characters
| var context = this; | |
| this.get('#/', function() { | |
| this.trigger('myEvent', { h1: 'My app', text: 'world' }); | |
| }); |
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 characters
| this.bind('myEvent', function(e, opts) { | |
| $('h1').html(opts.h1); | |
| $('p#text').html(context.url.build('hello', opts.text)); | |
| }); |
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 characters
| this.url = { | |
| build: function(key, val) { | |
| return '#/'+key+'/'+val; | |
| } | |
| }; |
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 characters
| describe('myEvent', function() { | |
| beforeEach(function() { | |
| loadFixtures('fixtures/test.html'); | |
| opts = { | |
| h1: 'My app', | |
| text: 'world' | |
| }; | |
| app.trigger('myEvent', opts); | |
| }); | |
| it('should set h1', function() { | |
| expect($('h1')).toHaveText(opts.h1); | |
| }); | |
| it('should show something in place of default text', function() { | |
| expect($('p#text')).not.toHaveText('Replace me'); | |
| expect($('p#text')).not.toBeEmpty(); | |
| }); | |
| }); | |
| describe('url', function() { | |
| describe('build', function() { | |
| it('should return properly formed hash-based url', function() { | |
| var url = app.url.build('foo', 'bar'); | |
| expect(url).toEqual('#/foo/bar'); | |
| }); | |
| }); | |
| }); |
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 characters
| beforeEach(function() { | |
| loadFixtures('fixtures/test.html'); | |
| opts = { | |
| h1: 'My app', | |
| text: 'world' | |
| }; | |
| app.trigger('myEvent', opts); | |
| }); |
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 characters
| it('should set h1', function() { | |
| expect($('h1')).toHaveText(opts.h1); | |
| }); | |
| it('should show something in place of default text', function() { | |
| expect($('p#text')).not.toHaveText('Replace me'); | |
| expect($('p#text')).not.toBeEmpty(); | |
| }); |
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 characters
| describe('myEvent', function() { | |
| beforeEach(function() { | |
| $('body').append('<div id="jasmine"><h1>Heading</h1><p id="text">Replace me</p></div>'); | |
| opts = { | |
| h1: 'My app', | |
| text: 'world' | |
| }; | |
| app.trigger('myEvent', opts); | |
| }); | |
| afterEach(function() { | |
| $('div#jasmine').empty().remove(); | |
| }); | |
| it('should set h1', function() { | |
| expect($('h1').html()).toMatch(/My app/); | |
| }); | |
| it('should show something in place of default text', function() { | |
| expect($('p#text').html()).not.toMatch(/Replace me/); | |
| expect($('p#text').html().length).toBeGreaterThan(0); | |
| }); | |
| }); | |
| describe('url', function() { | |
| describe('build', function() { | |
| it('should return properly formed hash-based url', function() { | |
| var url = app.url.build('foo', 'bar'); | |
| expect(url).toEqual('#/foo/bar'); | |
| }); | |
| }); | |
| }); |
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 characters
| it('should set h1', function() { | |
| expect($('h1').html()).toMatch(/My app/); | |
| }); |
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 characters
| beforeEach(function() { | |
| $('body').append('<div id="jasmine"><h1>Heading</h1><p id="text">Replace me</p></div>'); | |
| opts = { | |
| h1: 'My app', | |
| text: 'world' | |
| }; | |
| app.trigger('myEvent', opts); | |
| }); | |
| afterEach(function() { | |
| $('div#jasmine').empty().remove(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment