简体   繁体   中英

Pass parameters to a method which is expected to throw an error?

First steps with QUnit. Apologies if this is hyper-simple. I'm trying to understand things from this page of the manual.

If I have this:

QUnit.test( 'test init throws', function( assert ){
    assert.throws( loader.init, 'some message' )
});

... is there any way to pass parameters to that call to function init( param1, param2 ) ?

You can use JavaScript's bind functionality for this, which will return a function with the parameters bound to it, by doing something of the form (where here we'd be passing in arg1 and arg2 ):

QUnit.test('test init throws', function(assert){
    assert.throws(loader.init.bind(loader, arg1, arg2), 'some message')
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM