Jest: test Intl.DateTimeFormat

后端 未结 3 897
星月不相逢
星月不相逢 2021-02-19 12:06

I would like to test a filter function I wrote which return a date formatted using Intl.DateTimeFormat(\'en-GB\', options):

// module \"date.js\"
export default          


        
3条回答
  •  忘了有多久
    2021-02-19 12:12

    In package.json add the intl package

     "intl": "*",
    

    In the jest.config.js

    module.exports = {
        moduleNameMapper: {
            Intl: '/node_modules/intl/'
        }
    };
    

    Then in Date.spec.js

     describe(`Date by locale`, () => {
         beforeAll(() => {  global.Intl = require('intl'); });
        // Add your tests here. 
        // Add a temporary console.log to verify the correct output
     }
    

提交回复
热议问题