m-radzikowski / aws-sdk-client-mock

AWS JavaScript SDK v3 mocks for easy unit testing. 🖋️ Typed 🔬 Tested 📄 Documented 🛠️ Maintained
https://m-radzikowski.github.io/aws-sdk-client-mock/
MIT License
812 stars 40 forks source link

Fail to stub entirely QueryCommand - DynamoDB #204

Closed SteveAldrin closed 10 months ago

SteveAldrin commented 10 months ago

Checklist

Bug description

Hi there,

I'm strungling with some tests, I only succeed to resolve with "anyCommand", with on("QueryCommand") it doesn't work. I've had no problems with other clients.

Any clue or idea to resolve this ?

ps: I also tried to reject but in the same way, I was not surprised I didn't work.

Reproduction

    const { QueryCommand } = require('@aws-sdk/lib-dynamodb');

    beforeEach(() => {
        dynamoDBMock = mockClient(globalDynamoDBDocumentClient);
    });
    it.only('should work with type and year 2021', async function () {
        // dynamoDBMock.onAnyCommand().resolves(fakeDAO.entityLow.queryResult);  // resolves rightly
        dynamoDBMock.on(QueryCommand).resolves(fakeDAO.entityLow.queryResult); // resolves undefined 

        await StockService.getStockTransfers('BL', '2021') // -> call of DynamoDBDocumentClient.send(new QueryCommand(awsParams)
        dynamoDBMock.commandCalls(QueryCommand);
    });

Environment

m-radzikowski commented 10 months ago

Hey, please provide a minimal reproductible example that includes all the code needed to run the test (like creating the client instance and sending the command).

SteveAldrin commented 10 months ago

Hi, I succeed, it was on my side, I use an other lib which include its own dependency on the aws-sdk... So the matcher didn't match, my bad !

Anyway, your lib is great !