-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
todos, context type tests in message type tests, cleaning up shortcut…
… type tests.
- Loading branch information
Filip Maj
committed
Sep 17, 2024
1 parent
8ebda18
commit abfe302
Showing
5 changed files
with
719 additions
and
1,092 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,39 @@ | ||
import { expectError, expectType } from 'tsd'; | ||
import type { GlobalShortcut, MessageShortcut, SayFn } from '../..'; | ||
import type { GlobalShortcut, MessageShortcut, SayFn, SlackShortcut } from '../..'; | ||
import App from '../../src/App'; | ||
|
||
const app = new App({ token: 'TOKEN', signingSecret: 'Signing Secret' }); | ||
|
||
// calling shortcut method with incorrect an type constraint value should not work | ||
// calling shortcut method with incorrect type constraint value should not work | ||
expectError( | ||
app.shortcut({ type: 'Something wrong' }, async ({ shortcut }) => { | ||
await Promise.resolve(shortcut); | ||
}), | ||
); | ||
|
||
// Shortcut in listener should be - MessageShortcut | ||
expectType<void>( | ||
app.shortcut({ type: 'message_action' }, async ({ shortcut }) => { | ||
expectType<MessageShortcut>(shortcut); | ||
await Promise.resolve(shortcut); | ||
}), | ||
); | ||
app.shortcut({ type: 'message_action' }, async ({ shortcut, say }) => { | ||
// Shortcut in listener should be MessageShortcut if type:message_action | ||
expectType<MessageShortcut>(shortcut); | ||
expectType<SayFn>(say); | ||
}); | ||
|
||
// If shortcut is parameterized with MessageShortcut, shortcut argument in callback should be type MessageShortcut | ||
expectType<void>( | ||
app.shortcut<MessageShortcut>({}, async ({ shortcut }) => { | ||
expectType<MessageShortcut>(shortcut); | ||
await Promise.resolve(shortcut); | ||
}), | ||
); | ||
app.shortcut<MessageShortcut>({}, async ({ shortcut, say }) => { | ||
expectType<MessageShortcut>(shortcut); | ||
expectType<SayFn>(say); | ||
}); | ||
|
||
expectType<void>( | ||
app.shortcut({}, async ({ shortcut, say }) => { | ||
expectType<SayFn | undefined>(say); | ||
await Promise.resolve(shortcut); | ||
}), | ||
); | ||
|
||
// If shortcut is parameterized with MessageShortcut, say argument in callback should be type SayFn | ||
expectType<void>( | ||
app.shortcut<MessageShortcut>({}, async ({ shortcut, say }) => { | ||
expectType<SayFn>(say); | ||
await Promise.resolve(shortcut); | ||
}), | ||
); | ||
// If the constraint is unspecific, say may be undefined and the shortcut is the more general SlackShortcut type | ||
app.shortcut({}, async ({ shortcut, say }) => { | ||
expectType<SlackShortcut>(shortcut); | ||
expectType<SayFn | undefined>(say); | ||
}); | ||
|
||
// If shortcut is parameterized with GlobalShortcut, say argument in callback should be type undefined | ||
expectType<void>( | ||
app.shortcut<GlobalShortcut>({}, async ({ shortcut, say }) => { | ||
expectType<undefined>(say); | ||
await Promise.resolve(shortcut); | ||
}), | ||
); | ||
app.shortcut<GlobalShortcut>({}, async ({ shortcut, say }) => { | ||
expectType<undefined>(say); | ||
expectType<GlobalShortcut>(shortcut); | ||
}); | ||
|
||
// TODO: test the Shortcut and Constraints type parameters and how they can rely on each other. | ||
// relates to https://github.com/slackapi/bolt-js/issues/796; proof out how the Shortcut type parameter can provide nice typing utilities for developers |
File renamed without changes.
Oops, something went wrong.