ipfs/test/__config__/jest.env.ts

19 lines
558 B
TypeScript

import Environment from 'jest-environment-jsdom'
/**
* A custom environment to set the TextEncoder required by ipfs-http-client.
*/
module.exports = class CustomTestEnvironment extends Environment {
async setup() {
await super.setup()
if (typeof this.global.TextEncoder === 'undefined') {
const { TextEncoder } = require('util')
this.global.TextEncoder = TextEncoder
}
if (typeof this.global.TextDecoder === 'undefined') {
const { TextDecoder } = require('util')
this.global.TextDecoder = TextDecoder
}
}
}