Jest: test Intl.DateTimeFormat

后端 未结 3 945
星月不相逢
星月不相逢 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:25

    You can use polyfill, as described here

    import IntlPolyfill from 'intl';
    import 'intl/locale-data/jsonp/ru';
    
    if (global.Intl) {
        Intl.NumberFormat = IntlPolyfill.NumberFormat;
        Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
    } else {
        global.Intl = IntlPolyfill;
    }
    

提交回复
热议问题