Skip to content

Commit

Permalink
Improve error message for when undefined is passed as token (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf committed Oct 14, 2021
1 parent bd86c9c commit bfc6e16
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
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(''))
})

0 comments on commit bfc6e16

Please sign in to comment.