Created
June 7, 2012 03:04
-
-
Save matthieua/2886287 to your computer and use it in GitHub Desktop.
Jasmine: Cheatsheet
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
// Jasmine Cheatsheet | |
// Resources | |
https://github.com/pivotal/jasmine-ajax //make ajax testing fun | |
http://sinonjs.org/ //stubing framework | |
http://johnbintz.github.com/jasmine-headless-webkit/ //headless testing | |
https://github.com/creynders/grunt-jasmine-task //headless testing | |
// Use guard-jasmine | |
gem "guard" | |
gem "jasmine" | |
gem "guard-jasmine" | |
gem "growl" | |
gem "rb-fsevent" | |
// run guard init | |
// in your Guardfile, specify the jasmine url and the specs files: | |
guard 'jasmine', :jasmine_url => 'http://localhost:8888/' do | |
watch(%r{spec/javascripts/.+Spec\.js$}) { "spec/javascripts" } | |
end | |
// run guard -g jasmine | |
// Jasmine jQuery Helper | |
URL: https://github.com/velesin/jasmine-jquery | |
describe("Experimentation", function() { | |
var elem; | |
beforeEach(function() { | |
elem = $('<div id="container"><p>Hello World</p></div>'); | |
}); | |
it("allows us to search with CSS selectors", function() { | |
expect(elem).toBe('#container'); | |
expect(elem).toContain('p'); | |
}); | |
it("detects whether an element has a class", function() { | |
expect(elem).not.toHaveClass('container'); | |
}); | |
it("detects whether an element has text", function() { | |
// expect(elem.children('p').text().match(/world/i)).toBeTruthy(); | |
expect(elem.children('p')).toHaveText(/world/i); | |
}); | |
it("should detect if an input has a value", function() { | |
var input = $('<input value=myValue>'); | |
expect(input).toHaveValue('myValue'); | |
}); | |
}); | |
// Fixtures | |
describe("Learning About Fixtures", function() { | |
it("offers three crucial functions", function() { | |
// readFixtures | |
// setFixtures | |
// loadFixtures | |
expect(readFixtures).toBeDefined(); | |
expect(setFixtures).toBeDefined(); | |
expect(loadFixtures).toBeDefined(); | |
}); | |
it("can load fixtures from a file", function() { | |
loadFixtures('fragment.html'); | |
expect( $('.fragment')).toExist(); | |
}); | |
it("can read fixtures without appending to DOM", function() { | |
var fixture = readFixtures('fragment.html'); | |
expect(fixture).toContain('li'); | |
expect( $(fixture).find('li') ).toHaveText('Add some data.'); | |
}); | |
it("can also receive the fixture as a parameter", function() { | |
setFixtures('<div class="sandbox">hello there</div>'); | |
expect($('.sandbox')).toExist(); | |
}); | |
it("offers a sandbox function for convenience", function() { | |
expect(sandbox).toBeDefined(); | |
setFixtures( sandbox({ 'class': 'some-class'}) ); | |
expect( $('.some-class')).toExist(); | |
expect( $('#sandbox') ).toHaveClass('some-class'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment