Skip to content

Commit 3fa7261

Browse files
authored
Merge pull request #259 from ftonato/tests/add-generic-tests
tests: create some generic tests
2 parents d476da7 + de2cbe2 commit 3fa7261

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

test/SupabaseAuthClient.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { SupabaseAuthClient } from '../src/lib/SupabaseAuthClient'
2+
3+
const DEFAULT_OPTIONS = {
4+
schema: 'public',
5+
autoRefreshToken: true,
6+
persistSession: true,
7+
detectSessionInUrl: true,
8+
headers: {},
9+
}
10+
const settings = { ...DEFAULT_OPTIONS }
11+
12+
test('it should create a new instance of the class', () => {
13+
const authClient = new SupabaseAuthClient(settings)
14+
expect(authClient).toBeInstanceOf(SupabaseAuthClient)
15+
})

test/client.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import { createClient } from '../src/index'
1+
import { createClient, SupabaseClient } from '../src/index'
22

33
const URL = 'http://localhost:3000'
44
const KEY = 'some.fake.key'
55

66
const supabase = createClient(URL, KEY)
77

8-
test('Build to succeed', async () => {
9-
// Basic test to ensure TS build is working.
10-
expect(true).toEqual(true)
8+
test('it should create the client connection', async () => {
9+
expect(supabase).toBeDefined()
10+
expect(supabase).toBeInstanceOf(SupabaseClient)
11+
})
12+
13+
test('it should throw an error if no valid params are provided', async () => {
14+
expect(() => createClient('', KEY)).toThrowError('supabaseUrl is required.')
15+
expect(() => createClient(URL, '')).toThrowError('supabaseKey is required.')
1116
})
1217

1318
// Socket should close when there are no open connections

test/constants.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { DEFAULT_HEADERS } from '../src/lib/constants'
2+
import { version } from '../src/lib/version'
3+
4+
test('it has the correct type of returning with the correct value', () => {
5+
const expected = {
6+
'X-Client-Info': `supabase-js/${version}`,
7+
}
8+
expect(DEFAULT_HEADERS).toEqual(expected)
9+
expect(typeof DEFAULT_HEADERS).toBe('object')
10+
expect(typeof DEFAULT_HEADERS['X-Client-Info']).toBe('string')
11+
expect(Object.keys(DEFAULT_HEADERS).length).toBe(1)
12+
})

0 commit comments

Comments
 (0)