tddjs > p255 stub
あるプログラムが他のプログラムを呼び出す際に仲介となるプログラム。
by s_hiroshi
HTML
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css">
<h1 id="qunit-header">QUnit example</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
JavaScript
function stubFn(returnValue) {
var fn = function() {
fn.called = true;
fn.args = arguments;
return returnValue;
};
fn.called = false;
return fn;
}
var f = stubFn({
x: 'a',
y: 'b'
});
test('stub test', function() {
var actual = {
x: 'a',
y: 'b'
}
deepEqual(actual, f(), 'actual deep equal f()');
ok(f.called, 'f.called is true');
});