Skip to content

Conversation

PeterAlfredLee
Copy link
Member

The test 'minimumFractionDigits, maximumFractionDigits' failed with log

● n › minimumFractionDigits, maximumFractionDigits

    expect(received).toEqual(expected) // deep equality

    Expected: "$0.99"
    Received: "US$ 0.99"

      746 |       }
      747 |     })
    > 748 |     expect(n(0.99, { key: 'currency', fallbackWarn: false })).toEqual('$0.99')
          |                                                               ^
      749 |     expect(n(1.1111, { key: 'decimal', fallbackWarn: false })).toEqual('1.11')
      750 |   })
      751 | 

      at Object.<anonymous> (packages/vue-i18n/test/composer.test.ts:748:63)

This problem is caused by the Intl.NumberFormat : we are testing with locale US, which is not supported locale

const locales1 = ['US', 'en-US'];
const options1 = { localeMatcher: 'lookup' };

console.log(Intl.NumberFormat.supportedLocalesOf(locales1, options1));

Therefore, the output of Intl.NumberFormat wil be decided by the runtime's default locale. This could be tested with

console.log(new Intl.NumberFormat('US', { style: 'currency', currency: 'USD' }).format(123456.789));

I'm using Windows and Ubuntu20.04 with language of Chinese, and I'm getting the US$123,456.79 instead of $123,456.79.

Related to issue #262

@kazupon kazupon added the Type: Refactoring A code change that neither fixes a bug nor adds a feature label Dec 28, 2020
Copy link
Member

@kazupon kazupon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kazupon kazupon merged commit d537af6 into intlify:master Dec 28, 2020
@PeterAlfredLee PeterAlfredLee deleted the fix_test_fail branch December 29, 2020 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Refactoring A code change that neither fixes a bug nor adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants