Braintree-web: `Cannot read property 'sjcl' of undefined`

Created on 27 Oct 2016  Â·  10Comments  Â·  Source: braintree/braintree-web

I'm attempting run my tests using ava and jsdom but I get the error Cannot read property 'sjcl' of undefined from braintree-web.

I haven't been able to find any helpful resources on how this should be handled in headless testing.

Most helpful comment

@SokratisVidros @clindsey

Add global.Braintree = {}; in your set up file and it should work.

All 10 comments

Can you make a repo with a reproducible case for this?

Also, what version of braintree-web are you using?

@clindsey I'm going to close this, since we haven't received a response from you, but if you still need help, feel free to re-open this issue.

I am also facing the same issue using mocha, sinon and jsdom.

TypeError: Cannot read property 'sjcl' of undefined
    at Object.<anonymous> (..my_project/node_modules/braintree-web/dist/braintree.js:5:26279)
    at Object.i.189 (..my_project/node_modules/braintree-web/dist/braintree.js:5:27655)
    at o (..my_project/node_modules/braintree-web/dist/braintree.js:3:561)
    at ..my_project/node_modules/braintree-web/dist/braintree.js:3:612
    at Object.i.188.187 (..my_project/node_modules/braintree-web/dist/braintree.js:5:25888)
    at o (..my_project/node_modules/braintree-web/dist/braintree.js:3:561)
    at ..my_project/node_modules/braintree-web/dist/braintree.js:3:612
    at Object.<anonymous> (..my_project/node_modules/braintree-web/dist/braintree.js:5:1145)
    at Object.i.163.14 (..my_project/node_modules/braintree-web/dist/braintree.js:5:4089)
    at o (..my_project/node_modules/braintree-web/dist/braintree.js:3:561)

Any help would be greatly appreciated.

Looks like you're using v2 of braintree-web. If you're not using Drop-In, I'd recommend upgrading to v3 of braintree-web, which is requirable in non-browser environments.

If you are using Drop-In, you will likely have to mock the global window object and various browser specific APIs.

If you provide a simple reproducible example, I will attempt to help you with it.

I am afraid i have to use the v2 and the drop-in UI as my payment form is enclosed in a shadow root.
In my JSDom setup file the window object as well as various namespaces are mocked. Do you have a rough estimate of what needs to be mocked?

Thanks!

If you make a minimal github repo or gist that illustrates the problem, I'm happy to take a look at it.

I've prepared a gist with my JSDOM setup. The error is invoked before the actual test code starts running.

https://gist.github.com/SokratisVidros/e4350345e8722c51f8210e99c7630d6d

@SokratisVidros @clindsey

Add global.Braintree = {}; in your set up file and it should work.

Worked like a charm! Thanks a lot!

Regards,


_Sokratis Vidros_
Senior Software Engineer @ Workable http://workable.com/

2016-11-03 16:55 GMT+02:00 Blade Barringer [email protected]:

@SokratisVidros https://github.com/SokratisVidros @clindsey
https://github.com/clindsey

Add global.Braintree = {}; in your set up file and it should work.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/braintree/braintree-web/issues/228#issuecomment-258166156,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABSi5tzJ5vZlehSq2MuC4JfCVaZFfa2Rks5q6fXSgaJpZM4KhxWB
.

Was this page helpful?
0 / 5 - 0 ratings