'jest error when trying to do unit test for functions in class in react native
in accountManager.js I defined AccountManagement Class and export some functions.
class AccountManagement extends BaseManagement {
defaultState = {};
reduxType = 'SET_WALLET';
constructor(state, type = 'SET_WALLET') {
super(state, type);
}
...
}
let instance = AccountManagement;
export default {
init(state = {}) {
instance = new AccountManagement(state);
return instance;
},
get state() {
const wallets = instance.internalState;
return wallets
},
...
}
in accountManagement.test.js
I was trying to make test code with the class.
import accountManagement from './accountManagement';
describe('accountManagement', () => {
it('should set default state', () => {
const manager = accountManagement.init();
console.log(manager);
})
})
I really do not know why manager is undefined.
If I delete the export default object and change to export default class AcccountManagement = {...}, it works.
I really cannot figure this out.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
