Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

node.js - global is not defined in jest test file

global variable in JS is not able to access in jest test files, also not able to change the values which are already defined in global.

the work around I have did is as follow:

require('./../../../../bin/global');

describe('gloablAccessMethod', () => {
    beforeEach(() => {
        // jest.spyOn(regionConfig,'global.regionConfig').mockImplementation(() => ({
        //     'ENABLE_CONFIG' : false
        // }));
        global.regionConfig.ENABLE_CONFIG = false;
    });

    const PHONE_PREFIX_SG = 65;
    it('should access mock global variables', () =>{
      //some sample tests
    });
});
question from:https://stackoverflow.com/questions/66047781/global-is-not-defined-in-jest-test-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...