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

[Jest] Cannot read property 'createMask' of undefined #225

Closed
listepo-alterpost opened this issue Jul 31, 2019 · 24 comments
Closed

[Jest] Cannot read property 'createMask' of undefined #225

listepo-alterpost opened this issue Jul 31, 2019 · 24 comments

Comments

@listepo-alterpost
Copy link
Contributor

listepo-alterpost commented Jul 31, 2019

Cannot read property 'createMask' of undefined for jest, when import import IMask from 'imask';

@listepo-alterpost
Copy link
Contributor Author

const imask = require('imask'); works, but I really would not like to go to such extremes

@listepo-alterpost
Copy link
Contributor Author

listepo-alterpost commented Jul 31, 2019

I think a problem with UMD and node support

@listepo-alterpost
Copy link
Contributor Author

@listepo-alterpost listepo-alterpost changed the title Cannot read property 'createMask' of undefined [Jest] Cannot read property 'createMask' of undefined Jul 31, 2019
@listepo-alterpost
Copy link
Contributor Author

listepo-alterpost commented Jul 31, 2019

Also works like import * as IMask from 'imask'; but without ts typings

@uNmAnNeR
Copy link
Owner

uNmAnNeR commented Aug 1, 2019

I think adding esm build (module in package.json) for imask should help. But needs some time as usual )

@uNmAnNeR
Copy link
Owner

uNmAnNeR commented Aug 2, 2019

@listepo-alterpost can you please check #226

@listepo-alterpost
Copy link
Contributor Author

listepo-alterpost commented Aug 2, 2019

still failed, jest using dist/imask.js

@listepo-alterpost
Copy link
Contributor Author

listepo-alterpost commented Aug 2, 2019

I think dist/imask.js should contain export default polyfill for node

@listepo-alterpost
Copy link
Contributor Author

@uNmAnNeR
Copy link
Owner

uNmAnNeR commented Aug 2, 2019

Actually it is already done for umd build by rollup.

@listepo-alterpost
Copy link
Contributor Author

but the problem remains

@uNmAnNeR
Copy link
Owner

uNmAnNeR commented Aug 2, 2019

Could you please check if import { default as IMask } from 'imask' is working or not?

@listepo-alterpost
Copy link
Contributor Author

still failed

@uNmAnNeR
Copy link
Owner

uNmAnNeR commented Aug 3, 2019

No more ideas so far. If 'require' is working than probably issue relates to building jest tests. I have not used it so can not reason about.

@listepo-alterpost
Copy link
Contributor Author

I will try to find a solution

@uNmAnNeR
Copy link
Owner

@listepo-alterpost hi! may be it will help #235

@uNmAnNeR
Copy link
Owner

should be fixed now

@listepo-alterpost
Copy link
Contributor Author

@uNmAnNeR thanks

@tarmooo
Copy link

tarmooo commented Dec 2, 2019

For me this still seems to fail as i import it like that

import IMask from 'imask'

and use it:
this.imask = IMask(inputElement, { mask })

Then JEST screams at me: TypeError: Cannot read property 'Masked' of undefined

@uNmAnNeR
Copy link
Owner

uNmAnNeR commented Dec 4, 2019

@tarmooo try import { default as IMask } from 'imask'.

@tarmooo
Copy link

tarmooo commented Dec 4, 2019

thank you for your reply @uNmAnNeR, but still same, also tried other import methods that are referenced in this issue
TypeError: Cannot read property 'Masked' of undefined

  at createMask (node_modules/imask/src/masked/factory.js:34:31)
  at new InputMask (node_modules/imask/src/controls/input.js:49:19)
  at Object.IMask [as default] (node_modules/imask/dist/imask.js:4591:11)

I use imask inside stenciljs if that matters at all.

@uNmAnNeR
Copy link
Owner

uNmAnNeR commented Dec 4, 2019

Ok, seems that problem is not in import.
Let me explain and you will be able to check. IMask uses global object to resolve circular dependencies. Global object varies depending on environment: https://github.com/uNmAnNeR/imaskjs/blob/master/packages/imask/src/core/utils.js#L123

So it seems that your globals has been changed from moment where scripts are imported and when tests are executing. So check if it's possible to keep globals.

@uNmAnNeR
Copy link
Owner

@tarmooo Hi! i've just commited db7a14d new way to resolve globals inside mask. Can you please check if it solves your problem?

@tarmooo
Copy link

tarmooo commented Dec 12, 2019

@tarmooo Hi! i've just commited db7a14d new way to resolve globals inside mask. Can you please check if it solves your problem?

Yes, that actually fixed it. At least my snapshot tests are running now. Good job :) Waiting for release because it is not possible to install pacakge from subdirectory sadly.

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

No branches or pull requests

3 participants