Class('Test.Run.Test.Browser', {
isa : Test.Run.Test,
have : {
iframe : null,
timeoutIds : null,
finished : false
},
after : {
initialize : function () {
this.timeoutIds = {}
}
},
methods : {
beginAsync : function (time) {
var me = this
var timeoutId = this.topScope.setTimeout(function () {
me.endAsync(timeoutId)
}, time || 1e4)
this.timeoutIds[timeoutId] = true
return timeoutId
},
endAsync : function (timeoutId) {
var counter = 0
if (!timeoutId) Joose.O.each(this.timeoutIds, function (value, name) {
timeoutId = name
if (counter++) throw "Calls to endAsync without argument should only be performed if you have single beginAsync statement"
})
this.topScope.clearTimeout(timeoutId)
delete this.timeoutIds[timeoutId]
if (this.finished) this.finalize()
},
finalize : function () {
this.finished = true
if (!Joose.O.isEmpty(this.timeoutIds)) return
this.SUPER()
}
}
})
//eof Test.Run.Test.Browser
/**
Name
====
Test.Run.Test.Browser - Base class for test file, running on the browser platform.
SYNOPSIS
========
t.plan(1)
var async0 = t.beginAsync()
use('Module.Stub', function () {
//=========================================
t.diag('Sanity')
t.ok(Module.Stub, "Module.Stub is here")
t.endAsync(async0)
})
DESCRIPTION
===========
`Test.Run.Test.Browser` is a base testing class for tests, running on browser. It assumes the presence of `setTimeout/clearTimeout` functions and provides the ability of asynchornous testsing.
ISA
===
[Test.Run.Test]
DOES
====
None
USAGE
=====
Below is the list of methods, intended for usage in the individual tests.
### beginAsync
> `Number beginAsync(Number? maxTime)`
> This method starts the "asynchronous frame". The test will not finished, until the frame will not be finished with [endAsync] call.
[endAsync] will be automatically call after specified `maxtime`.
> **maxTime** - the maximum time (in ms) to wait until explicitly finalize this async frame.
> *return* - The timeoutId, which can be used in [endAsync] call
### endAsync
> `void endAsync(Number timeoutId)`
> This method finalize the "asynchronous frame" started with [beginAsync].
> **timeoutId** - The timeoutId, returned by [beginAsync] call
ATTRIBUTES
==========
### timeoutIds
> `Object timeoutIds`
> The hash which keep the timeout ids, generated by [beginAsync] call
### finished
> `Boolean finished`
> The sign whether this test has finished execution (its 'run' function was executed). Test still may be active, until there are active "asynchronous frames"
SEE ALSO
========
Additional general-purpose assertions checks: [Test.Run.Test.More]
General documentation for Joose: [http://openjsan.org/go/?l=Joose](http://openjsan.org/go/?l=Joose)
BUGS
====
All complex software has bugs lurking in it, and this module is no exception.
Please report any bugs through the web interface at [http://github.com/SamuraiJack/Module-Stub/issues](http://github.com/SamuraiJack/Module-Stub/issues)
AUTHORS
=======
Nickolay Platonov [nplatonov@cpan.org](mailto:nplatonov@cpan.org)
COPYRIGHT AND LICENSE
=====================
Copyright (c) 2009, Nickolay Platonov
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Nickolay Platonov nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[Test.Run.Test]: ../Test.html
[Test.Run.Test.More]: More.html
*/