-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
td.replaced module still returning stub after a td.reset() #373
Comments
Thank you for this example. Seems like a bug as far as I can tell by glancing at it. We'll want to start with a reproducing test in the build. |
If there's anything else I can help with please let me know! |
If you'd like to send a PR to add a failing test reproducing this to our |
Sure thing, I'll see can I get it in this evening. Is there a prefered suite you'd like this added to? |
yes, look under |
I attempted to replicate the issue in the TestDouble repo yesterday evening and wasn't successful. I went so far as to replicate nearly exactly the code that I have in my project with the exception of adding Typescript and transpiling. After this failed I went back to my project to see if there is anything I could change in my function that may make it easier to test. So I changed the function from a non-default export to a static function on a default export like so. I did this as I had other dependencies that were resetting correctly and this was the only difference. import * as AWS from 'aws-sdk';
export default class S3Helper {
public static getFileFromS3(Bucket: string, Key: string): Promise<any> {
const S3 = new AWS.S3();
return S3.getObject({ Bucket, Key }).promise();
}
} After doing this all my tests started working as expected... Not sure if this is helpful or not |
I don't really understand why this worked, but I'm going to close until we can reproduce. Usually the reason this sort of thing "fixes" the problem is because some module somewhere is doing something to cache itself on first load outside the normal Node.js module cache, which in turn defeats how |
Description
calling
td.replace
a second time on an imported module still resolves the originaltd.replace
Is it possible to td.replace the same module more than once between different describe blocks?Issue
td.reset() doesn't seem to reset a replaced module.
I have a module that exports a non default function that returns a promise.
The setup/teardown and sample tests are as follows.
My expectation is that after the final td.reset() in the first describe block I should be able to once again replace the
s3_helper
to this time reject the promise to cover my other test cases. Having debugged my unit tests I have found this not to be then case and whatever I replace the module with originally is returned even after subsiquent replace calls.When the second test is run in isolation or moved to execute first it works as expected. So more than likely this is to do with me incorrectly setting up my tests.
Environment
node -v
: 8.9.4npm -v
: 5.6.0testdouble@3.8.1
:The text was updated successfully, but these errors were encountered: