Skip to content
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

Improve error message for when undefined is passed as token #47

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deno/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class Bot<
*/
constructor(public readonly token: string, config?: BotConfig<C>) {
super()
if (token.length === 0) throw new Error('Empty token!')
if (!token) throw new Error('Empty token!')
this.me = config?.botInfo
this.clientConfig = config?.client
this.ContextConstructor =
Expand Down
3 changes: 2 additions & 1 deletion deno/test/bot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
assertEquals,
} from 'https://deno.land/[email protected]/testing/asserts.ts'

function createBot(token = 'fake-token') {
function createBot(token: string) {
return new Bot(token)
}

Expand All @@ -14,5 +14,6 @@ Deno.test('should take a token', () => {
})

Deno.test('should not take an empty token', () => {
assertThrows(() => createBot(undefined as unknown as string))
assertThrows(() => createBot(''))
})