/cypress/component/advanced/i18n/i18next-spec.js

https://github.com/bahmutov/cypress-react-unit-test · JavaScript · 48 lines · 38 code · 9 blank · 1 comment · 0 complexity · 5175112f89049d7eba9bd8cc7a9a6943 MD5 · raw file

  1. /// <reference types="cypress" />
  2. import * as React from 'react'
  3. import i18n from './i18n'
  4. import { LocalizedComponent } from './LocalizedComponent'
  5. import { mount } from 'cypress-react-unit-test'
  6. import { I18nextProvider } from 'react-i18next'
  7. describe('i18n', () => {
  8. const localizedMount = (node, { locale }) => {
  9. mount(
  10. <I18nextProvider i18n={i18n.cloneInstance({ lng: locale })}>
  11. {node}
  12. </I18nextProvider>,
  13. )
  14. }
  15. it('Plural in en', () => {
  16. localizedMount(<LocalizedComponent count={15} name="Josh" />, {
  17. locale: 'en',
  18. })
  19. cy.contains('Hello Josh, you have 15 unread messages.')
  20. })
  21. it('Single in en', () => {
  22. localizedMount(<LocalizedComponent count={1} name="Josh" />, {
  23. locale: 'en',
  24. })
  25. cy.contains('Hello Josh, you have 1 unread message.')
  26. })
  27. it('Plural in ru', () => {
  28. localizedMount(<LocalizedComponent count={15} name="Костя" />, {
  29. locale: 'ru',
  30. })
  31. cy.contains('Привет, Костя, y тебя 15 непрочитанных сообщений.')
  32. })
  33. it('Single in ru', () => {
  34. localizedMount(<LocalizedComponent count={1} name="Костя" />, {
  35. locale: 'ru',
  36. })
  37. cy.contains('Привет, Костя, y тебя 1 непрочитанное сообщение.')
  38. })
  39. })