jumpsuit icon indicating copy to clipboard operation
jumpsuit copied to clipboard

How can I test Jumpsuit components?

Open razvanilin opened this issue 8 years ago • 5 comments

Hi people,

I created a simple app with create-react-app where I installed jumpsuit. I made some small changes to the main app component by importing Link from jumpsuit. After doing this, the sample test that checks if the component renders correctly gives me this error:

> node scripts/test.js --env=jsdom
 FAIL  src/containers/App.test.js
  ● Test suite failed to run
    Invalid Adapter: undefined
      
      at new PouchDB$3 (node_modules/pouchdb-browser/lib/index.js:2797:11)
      at Object.<anonymous> (node_modules/jumpsuit/lib/hsrPouch.js:13:10)
      at Object.<anonymous> (node_modules/jumpsuit/lib/hsr.js:16:17)
      at Object.<anonymous> (node_modules/jumpsuit/lib/index.js:23:12)
      at Object.<anonymous> (src/containers/App.js:2:43)
      at Object.<anonymous> (src/containers/App.test.js:3:38)
      at process._tickCallback (internal/process/next_tick.js:103:7)
Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.718s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

The only thing I have to do to App.js is to import Link:

import { Link } from 'jumpsuit';

Do I have to write extra code to my test in order to get it working? Seems like I have to define a PouchDB adapter.

The current code looks like this:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
  const div = document.createElement('div');
  ReactDOM.render(<App />, div);
});
$ npm -v
3.10.9
$ node -v
v7.2.0

OS: Windows 10

Will appreciate any help on this. Cheers!

razvanilin avatar Feb 23 '17 20:02 razvanilin

I have the same problem with import { Component } from 'jumpsuit'; I don't think the problem is related to Link

diegobfernandez avatar Feb 23 '17 21:02 diegobfernandez

Does the app render in the browser still? Or is it just the test that fails?

tannerlinsley avatar Feb 23 '17 22:02 tannerlinsley

Just the test fails. No problems with the browser rendering.

razvanilin avatar Feb 23 '17 22:02 razvanilin

Any update to getting the tests to work @tannerlinsley ? I know you're busy, just wondered if this is in the works to be fixed soon. Thanks for all you've done for this!

briancbarrow avatar Mar 25 '17 04:03 briancbarrow

Not using Jumpsuit I would suppose the error is that you are not using Jumpsuit in a Browser context. The code from Jumpsuit is:

const db = new PouchDB('jumpsuit_hsr')

(see https://github.com/jumpsuit/jumpsuit/blob/5993629cb27fa24623a05956412ba300a3b69123/src/hsrPouch.js#L4)

In a Browser Context Pouch automatically uses some Adapter (IndexedDB, i think) whereas in a Node Context you have to specify the adapter. In order for this to work you would probably have to install pouchdb-adapter-node-websqlor pouchdb-adapter-memory via npm and change the line to

const db = new PouchDB('jumpsuit_hsr', {adapter: 'websql'})

See https://pouchdb.com/adapters.html#pouchdb_in_node_js for reference.

Or you change import PouchDB from 'pouchdb-browser' to import PouchDB from 'pouchdb' and install pouch via npm

djungowski avatar May 04 '17 12:05 djungowski