From 7561a6e121430f9ae6f819c938eb5ea7f79e2954 Mon Sep 17 00:00:00 2001 From: Christoforos Varakliotis Date: Sat, 25 Feb 2023 20:00:47 +0200 Subject: [PATCH] Basic Dev Mode tests (#70) * simple dev mode smoke test * update README: provide a valid example schema --- README.md | 1 + tests/devMode.test.tsx | 35 +++++++++++++++++++++++++++++++++++ tests/helpers.tsx | 2 ++ 3 files changed, 38 insertions(+) create mode 100644 tests/devMode.test.tsx diff --git a/README.md b/README.md index ec34bbd..2761332 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ const initialize = async () => { properties: { id: { type: 'string', + maxLength: 100, }, name: { type: 'string', diff --git a/tests/devMode.test.tsx b/tests/devMode.test.tsx new file mode 100644 index 0000000..0b947f7 --- /dev/null +++ b/tests/devMode.test.tsx @@ -0,0 +1,35 @@ +import React from 'react'; +import { setup, teardown, MyDatabase } from './helpers'; + +import { renderHook } from '@testing-library/react-hooks'; +import { addRxPlugin } from 'rxdb'; +import { RxDBDevModePlugin } from 'rxdb/plugins/dev-mode'; +import Provider from '../src/Provider'; +import { characters } from './mockData'; +import useRxDB from '../src/useRxDB'; + +addRxPlugin(RxDBDevModePlugin); + +describe('when RxDBDevModePlugin', () => { + let db: MyDatabase; + + beforeAll(async done => { + db = await setup(characters, 'characters'); + done(); + }); + + afterAll(async done => { + await teardown(db); + done(); + }); + + describe('useRxDB', () => { + it('should return the db instsance', () => { + const wrapper = ({ children }) => ( + {children} + ); + const { result } = renderHook(() => useRxDB(), { wrapper }); + expect(result.current).toBe(db); + }); + }); +}); diff --git a/tests/helpers.tsx b/tests/helpers.tsx index a07ee23..68db127 100644 --- a/tests/helpers.tsx +++ b/tests/helpers.tsx @@ -51,9 +51,11 @@ export const setupCollection = async ( properties: { id: { type: 'string', + maxLength: 100, }, name: { type: 'string', + maxLength: 100, }, affiliation: { type: 'string',