Skip to content

Commit 097c52d

Browse files
committed
Fix unit test
1 parent 540e742 commit 097c52d

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

packages/amazonq/test/unit/amazonq/lsp/chat/messages.test.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { AuthUtil } from 'aws-core-vscode/codewhisperer'
1010
import { registerMessageListeners } from '../../../../../src/lsp/chat/messages'
1111
import { AmazonQChatViewProvider } from '../../../../../src/lsp/chat/webviewProvider'
1212
import { secondaryAuth, authConnection, AuthFollowUpType } from 'aws-core-vscode/amazonq'
13+
import { messages } from 'aws-core-vscode/shared'
1314

1415
describe('registerMessageListeners', () => {
1516
let languageClient: LanguageClient
@@ -129,41 +130,33 @@ describe('registerMessageListeners', () => {
129130
})
130131

131132
describe('COPY_TO_CLIPBOARD', () => {
133+
let copyToClipboardStub: sinon.SinonStub
132134
const testCode = 'test'
133135
const copyMessage = {
134136
command: 'copyToClipboard',
135137
params: {
136138
code: testCode,
137139
},
138140
}
139-
let writeTextStub: sinon.SinonStub
140141

141142
beforeEach(() => {
142-
writeTextStub = sinon.stub()
143-
sandbox.stub(vscode.env, 'clipboard').value({
144-
writeText: writeTextStub,
145-
})
143+
copyToClipboardStub = sandbox.stub().resolves()
144+
sandbox.stub(messages, 'copyToClipboard').get(() => copyToClipboardStub)
146145
})
147146

148147
it('successfully copies code to clipboard', async () => {
149-
writeTextStub.resolves()
150-
151148
await messageHandler(copyMessage)
152149

153-
sinon.assert.calledWith(writeTextStub, testCode)
150+
sinon.assert.calledWith(copyToClipboardStub, testCode)
154151
})
155152

156153
it('handles clipboard copy failure', async () => {
157154
const errorMessage = 'Failed to copy'
158-
writeTextStub.rejects(new Error(errorMessage))
155+
copyToClipboardStub.rejects(new Error(errorMessage))
159156

160157
await messageHandler(copyMessage)
161158

162-
sinon.assert.calledOnce(errorStub)
163-
sinon.assert.calledWith(
164-
errorStub,
165-
sinon.match(`[VSCode Client] Failed to copy to clipboard: ${errorMessage}`)
166-
)
159+
sinon.assert.calledWith(errorStub, `[VSCode Client] Failed to copy to clipboard: ${errorMessage}`)
167160
})
168161
})
169162
})

0 commit comments

Comments
 (0)