-
Notifications
You must be signed in to change notification settings - Fork 40
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
Using mocks in multiple test files fails #64
Comments
Thank you for the detailed description and repo with reproduction! The problem seems to be that the The solution is to move const { ListBucketsCommand, S3Client } = require('@aws-sdk/client-s3');
const { mockClient } = require('aws-sdk-client-mock');
const assert = require('assert');
describe('one', () => {
let mock;
let client;
beforeEach(() => {
mock = mockClient(S3Client);
client = new S3Client();
});
it('should work', async () => {
mock.on(ListBucketsCommand).resolves({});
const result = await client.send(new ListBucketsCommand());
assert.deepEqual(result, {});
});
}); I will add this to the caveats section of the readme. This is not an issue with Jest, which probably separates execution environments for each test file. |
Do I have to use Have have a test where I define the describe('describe first test', () => {
let mock: AwsStub<ServiceInputTypes, ServiceOutputTypes, SSMClientResolvedConfig>
beforeEach(() => {
mock = mockClient(SSMClient)
})
it('test 1 has on', () => {
mock.on(GetParameterCommand).resolvesOnce({
Parameter: {
Name: 'parameterStore',
Value: 'value'
}
})
myTestObject.testMethod()
})
it('test 2 still has the on and i can not override', async () => {})
})
describe('next description still the defined mock', () => {
beforeEach(() => {
mockClient(SSMClient)
})
it('still', async () => {})
}) Also tried to use Is this a common problem or am i using it incorrectly |
@lynxSven Mock is not reset automagically between the tests. The |
The |
Checklist
Bug description
If we have mocks in multiple files, some of the test suites are failing.
If we run each file individually the tests succeed.
If we run mocha with
--parallel
it also worksSee repro here: https://github.com/danmana/mocha-aws-sdk-client-mock
npm run mocha -- tests/one*.js
worksnpm run mocha -- tests/two*.js
worksnpm run mocha -- tests/*.js
npm run mocha -- tests/*.js --parallel
worksAlso if we put all tests in the same file, it works.
The tests are pretty straight forward
This is probably due to the way mocha runs the tests, but I can't figure out how to fix it.
Environment
The text was updated successfully, but these errors were encountered: