QUnit.stack()


QUnit.stack( [offset ] )Returns: String

Description: Returns a single line string representing the stacktrace (call stack)

This method returns a single line string representing the stacktrace from where it was called. According to its offset argument, QUnit.stack() will return the correspondent line from the call stack.

The default offset is 0 and will return the current location where it was called.

Not all browsers support retrieving stracktraces. In those, QUnit.stack() will return undefined.

Example:

The stacktrace line can be used on custom assertions and reporters. The following example logs the line of each passing assertion.

1
2
3
4
5
6
7
8
9
10
11
12
13
QUnit.log( function( details ) {
if ( details.result ) {
// 5 is the line reference for the assertion method, not the following line.
console.log( QUnit.stack( 5 ) );
}
} );
QUnit.test( "foo", function( assert ) {
// the log callback will report the position of the following line.
assert.ok( true );
} );