mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2025-03-05 01:18:02 -05:00
Introduced qunit setup extension for future test rewrites
This commit is contained in:
parent
467827843b
commit
62dbbf47e3
2 changed files with 61 additions and 0 deletions
23
test/qunit_setup.coffee
Normal file
23
test/qunit_setup.coffee
Normal file
|
@ -0,0 +1,23 @@
|
|||
setupFn = -> null
|
||||
window.setup = (fn) ->
|
||||
setupFn = fn
|
||||
window.moreSetup = (fn) ->
|
||||
origSetup = setupFn
|
||||
setup ->
|
||||
origSetup.call(this)
|
||||
fn.call(this)
|
||||
window.clearSetup = ->
|
||||
setup -> null
|
||||
|
||||
originalModule = window.module
|
||||
window.module = (description) ->
|
||||
clearSetup()
|
||||
originalModule(description)
|
||||
|
||||
originalTest = window.test
|
||||
window.test = (description, testFn) ->
|
||||
setupSnapshot = setupFn
|
||||
originalTest description, ->
|
||||
context = {}
|
||||
setupSnapshot.call(context)
|
||||
testFn.call(context)
|
38
test/qunit_setup.js
Normal file
38
test/qunit_setup.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
(function() {
|
||||
var originalModule, originalTest, setupFn;
|
||||
setupFn = function() {
|
||||
return null;
|
||||
};
|
||||
window.setup = function(fn) {
|
||||
return (setupFn = fn);
|
||||
};
|
||||
window.moreSetup = function(fn) {
|
||||
var origSetup;
|
||||
origSetup = setupFn;
|
||||
return setup(function() {
|
||||
origSetup.call(this);
|
||||
return fn.call(this);
|
||||
});
|
||||
};
|
||||
window.clearSetup = function() {
|
||||
return setup(function() {
|
||||
return null;
|
||||
});
|
||||
};
|
||||
originalModule = window.module;
|
||||
window.module = function(description) {
|
||||
clearSetup();
|
||||
return originalModule(description);
|
||||
};
|
||||
originalTest = window.test;
|
||||
window.test = function(description, testFn) {
|
||||
var setupSnapshot;
|
||||
setupSnapshot = setupFn;
|
||||
return originalTest(description, function() {
|
||||
var context;
|
||||
context = {};
|
||||
setupSnapshot.call(context);
|
||||
return testFn.call(context);
|
||||
});
|
||||
};
|
||||
}).call(this);
|
Loading…
Reference in a new issue