TypeError while testing extended Immutable.List.sort() with jest
Hi @philpl ,
thx for your great work on extendable-iummutable, i've liked it so much.
But now i'm faced with weird error while trying to test my extended class with Jest, saying:
TypeError: Class constructor Second cannot be invoked without 'new'
while using immutable.reify
Here is my code:
import { fromJS } from 'immutable'
import { List } from 'extendable-immutable'
const list = fromJS([
{title: "A"},
{title: "E"},
{title: "B"},
{title: "D"},
{title: "C"},
])
const result = fromJS([
{title: "A"},
{title: "B"},
{title: "C"},
{title: "D"},
{title: "E"},
])
class Second extends List {
lol(){
return 'LOL:)'
}
}
const originalList = new List(list)
const secondList = new Second(list)
describe('original List', () => {
it('should return sorted list', () => {
expect(originalList.sort().toJS(), result)
})
})
describe('extended List', () => {
it('should return sorted list', () => {
expect(secondList.sort().toJS(), result)
})
it('should say LOL!', () => {
expect(secondList.lol(), "LOL:)")
})
})
Could you please help me to deal with it?
Can't manage to reproduce this: https://codesandbox.io/s/n05pjv292m
Can you provide a working reproduction please?
@philpl i can't figure out how to setup Jest tests in codesandbox. Is it possible there?
If not, u could simply copy my code and run it with jest locally (my version included in react-scripts is 20.0.4 now)
@alekseykarpenko yea, I don't think it's possible. But take a look at my codesandbox there and see if you can reproduce it with that one
@philpl it's reproducable only with jest! it's pointless to try it on codesandbox if no jest there 🤔
@alekseykarpenko Alright, can you try to create a minimal code snippet that reproduces the bug? Then I can try to narrow it down
@philpl code snippet is mentioned above. U can setup a blank app with create-react-app, insert that code into any test file like example.test.js and run yarn test
@alekseykarpenko It is not a minimal reproduction though. You can save me a lot of time by pushing your existing reproduction repo and/or minimising the reproduction above :wink:
Edit: To be a bit clearer on this, sorry, I'm not here to torment you 😆 but at this point you know the bug better than I do, so when you minimise and pin it down, it won't take you as long as it would take me
@philpl np, will try to push example repo asap. im still a little bit newbie to github best practices)
@philpl here you go. clone that repo, run yarn install and then yarn test
https://github.com/alekseykarpenko/extendable-immutable-jest-typeerror
@philpl were you able to reproduce that error?
+1 got this reproduced in similar situation, or we may be doing something wrong
hey guys, still experiencing this exact issue. have you managed to find a solution for this?
Otherwise extendable-immutable can't be used in anything that is planned to be covered with unit tests on Jest.
I've figured this out.
Here's a small reproducible case:
const { OrderedMap } = require('extendable-immutable')
class Collection extends OrderedMap {}
const magic = new Collection()
magic.filter(x => true)
Run that with Node.js and you'll get the error TypeError: Class constructor Collection cannot be invoked without 'new'.
Compile it with Babel down to ES5 first and there will be no error. This library is not compatible with ES6 and above.