You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to verify that a stub was called with a particular parameter, but also have that stub throw an error.
Issue
When a stub is configured to throw, attempting to verify it instead throws the configured error. (Also, my current attempt uses both .when and .verify on the same stub, which the docs suggest is incorrect anyway.)
Environment
node -v output: v10.8.0
npm -v (or yarn --version) output: 1.12.1
npm ls testdouble (or yarn list testdouble) version:
yarn list v1.12.1
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ testdouble@3.11.0
✨ Done in 0.56s.
Code-fenced Example
constassert=require('assert').strict;constexeca=require('execa');consttd=require('testdouble');functionsubject(){try{const{ stdout }=execa('foo');// throws if "foo" doesn't exist or has a non-zero exit codeconstmatch=/some (.+) string/.exec(stdout);returnmatch[1];}catch(ex){// log it}try{const{ stdout }=execa('bar');// throws if "bar" doesn't exist or has a non-zero exit codeconstmatch=/a different (.+) string/.exec(stdout);returnmatch[1];}catch(ex){// log itreturnnull;}}conststub=td.function(execa.sync);td.replace(execa,'sync',stub);td.when(stub(),{ignoreExtraArgs: true}).thenThrow(newError('command not found'));assert(null===subject());td.verify(stub('bar'),{ignoreExtraArgs: true});// throws "command not found" error
How should I instead be configuring/verifying this stub?
The text was updated successfully, but these errors were encountered:
This wouldn't be supported, as it falls under our advice not to verify what you stub. If the stubbing to throw an error is necessary, then an explicit verification would be redundant, as the stubbing would either be observable by the test directly (e.g. an error is thrown, as is the case here), or indirectly (the subject handles the error somehow and whatever it does next is asserted by the test).
Description
I need to verify that a stub was called with a particular parameter, but also have that stub throw an error.
Issue
When a stub is configured to throw, attempting to verify it instead throws the configured error. (Also, my current attempt uses both
.when
and.verify
on the same stub, which the docs suggest is incorrect anyway.)Environment
node -v
output: v10.8.0npm -v
(oryarn --version
) output: 1.12.1npm ls testdouble
(oryarn list testdouble
) version:yarn list v1.12.1
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ testdouble@3.11.0
✨ Done in 0.56s.
Code-fenced Example
How should I instead be configuring/verifying this stub?
The text was updated successfully, but these errors were encountered: