jedisct1 / libsodium.js

libsodium compiled to Webassembly and pure JavaScript, with convenient wrappers.
Other
968 stars 138 forks source link

Jest raises `Cannot read properties of undefined (reading 'sodium')` #315

Closed fboucquez closed 1 year ago

fboucquez commented 1 year ago

Hi team, jest is raising this error when trying to use a lib that depends on libsodium-wrappers

Minimal example:

import _sodium from 'libsodium-wrappers'

test('sodium', () => {
  console.log(_sodium)
})

Any hint how to fix it?

marcel-idana commented 1 year ago
import _sodium from 'libsodium-wrappers'

test('sodium', async () => {
  await _sodium.ready
  console.log(_sodium)
})

See https://github.com/jedisct1/libsodium.js#usage-as-a-module

Does this help?