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

TypeError: Illegal invocation when trying to start shim within jest #318

Open
tarjei opened this issue Apr 5, 2018 · 7 comments
Open

TypeError: Illegal invocation when trying to start shim within jest #318

tarjei opened this issue Apr 5, 2018 · 7 comments

Comments

@tarjei
Copy link

tarjei commented Apr 5, 2018

Hi, I tried to use indeeddbshim with FBs jest, but I got:

TypeError: Illegal invocation

Here's the stacktrace:
at Window.get [as indexedDB] (node_modules/indexeddbshim/dist/indexeddbshim-node.js:11625:33) at shim (node_modules/indexeddbshim/dist/indexeddbshim-node.js:11557:24) at IDBFactory.IDB.shimIndexedDB.__useShim (node_modules/indexeddbshim/dist/indexeddbshim-node.js:11619:21) at setGlobalVars (node_modules/indexeddbshim/dist/indexeddbshim-node.js:11798:35) at Object.<anonymous> (tests/setupTests.js:23:29)

And the testcode:

import setGlobalVars from 'indexeddbshim'
import Adapter from 'enzyme-adapter-react-16'
import { configure } from 'enzyme'

configure({ adapter: new Adapter() })

//global.window = global // We'll allow ourselves to use `window.indexedDB` or `indexedDB` as a global
setGlobalVars(global) // See signature below
@brettz9
Copy link
Collaborator

brettz9 commented Apr 9, 2018

Our previous version (and the one I've just added, 3.6.0) have this file a lot smaller in size than your stack trace would indicate, so I'm wondering whether you are testing against the latest version?

@rafayepes
Copy link

Some other example:

TypeError: Illegal invocation

      at Window.get [as indexedDB] (node_modules/indexeddbshim/dist/indexeddbshim-node.js:6890:35)
      at shim (node_modules/indexeddbshim/dist/indexeddbshim-node.js:6841:16)
      at IDBFactory.IDB.shimIndexedDB.__useShim (node_modules/indexeddbshim/dist/indexeddbshim-node.js:6884:17)
      at setGlobalVars (node_modules/indexeddbshim/dist/indexeddbshim-node.js:6988:27)
      at Object.<anonymous> (jest/testSetup.js:19:1)
          at Generator.next (<anonymous>)
          at new Promise (<anonymous>)
          at Generator.next (<anonymous>)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:118:7)

@ErikBjare
Copy link

I've reproduced (on accident), no clue what's going on.

@brettz9
Copy link
Collaborator

brettz9 commented Jun 25, 2018

We are attempting to follow the standardized interfaces precisely, and they are picky about how a property is accessed. What is your exact call to setGlobalVars?

As we needed a workaround for our own test environment, I put in a hack that checks for a shimNS on the this (e.g., window or global), and if present, it avoids the error. In the next version I think I will define this with config, but for now that might work as a workaround. But I'd still like to know how your Jest testSetup is invoking setGlobalVars. Thanks!

@andreujuanc
Copy link

I just got the same issue with jest. What's the workaround? if any.

@brettz9
Copy link
Collaborator

brettz9 commented Aug 8, 2018

Try setting global.shimNS = true against the code in master and see if that solves it.

@cbasah
Copy link

cbasah commented Oct 18, 2020

Try setting global.shimNS = true against the code in master and see if that solves it.

How do we set this in Jest? I get the same problem when doing a test on react-native expo app.

`
import React from 'react';
import renderer from 'react-test-renderer';

import App from './App';

describe('', () => {
it('has 1 child', () => {
const tree = renderer.create().toJSON();
expect(tree.children.length).toBe(1);
});
});
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants