Skip to content

Instantly share code, notes, and snippets.

@juno
Created December 24, 2010 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juno/753818 to your computer and use it in GitHub Desktop.
Save juno/753818 to your computer and use it in GitHub Desktop.
Jasmineによるdocument.getElementByIdのテスト
/**
* Document クラスのテスト
*/
describe('Document オブジェクトは', function() {
it('getElementById メソッドで特定の ID を持つ DOM オブジェクトを取得する事ができる', function() {
var elementId = 'test-node';
expect(document.getElementById(elementId)).not.toBeNull();
});
});
/**
* Document クラスのテスト
*/
describe('Document オブジェクトは', function() {
var container = null;
beforeEach(function() {
container = document.createElement('div');
container.id = 'test-node';
document.body.appendChild(container);
});
afterEach(function() {
document.body.removeChild(container);
container = null;
});
it('getElementById メソッドで特定の ID を持つ DOM オブジェクトを取得する事ができる', function() {
var elementId = 'test-node';
expect(document.getElementById(elementId)).not.toBeNull();
});
});
/**
* Document クラスのテスト
*/
describe('Document オブジェクトは', function() {
beforeEach(function() {
setFixtures('<div id="test-node"></div>');
});
it('getElementById メソッドで特定の ID を持つ DOM オブジェクトを取得する事ができる', function() {
var elementId = 'test-node';
expect(document.getElementById(elementId)).not.toBeNull();
});
});
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.0.1/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine-html.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/SpecHelper.js"></script>
<script type="text/javascript" src="spec/DocumentSpec.js"></script>
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment