Skip to content

Instantly share code, notes, and snippets.

@joecorcoran
Created September 1, 2010 14:14
Show Gist options
  • Save joecorcoran/560735 to your computer and use it in GitHub Desktop.
Save joecorcoran/560735 to your computer and use it in GitHub Desktop.
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('#/');
});
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;
}
};
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');
});
});
});
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('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');
});
});
});
it('should set h1', function() {
expect($('h1').html()).toMatch(/My app/);
});
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