Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

testing: simplify i18n mock creation #447

Closed
jpommerening opened this issue Apr 6, 2017 · 3 comments
Closed

testing: simplify i18n mock creation #447

jpommerening opened this issue Apr 6, 2017 · 3 comments

Comments

@jpommerening
Copy link
Member

Currently, creating an i18n mock requires an actual i18n instance:

const axI18nMock = createAxI18nMock( axI18n ); // :(

This is ok inside LaxarJS and bearable in widgets, but i18n instances are hard to come by when testing controls, leading to reimplementation of the i18n functionality, making tests prone to mask problems when the i18n API or behaviour changes.

It would be really nice if one could instead create an i18n mock with:

const axI18nMock = createAxI18nMock( axContextMock, axConfigurationMock ); // :)

(The need for this was identified in LaxarJS/laxar-mocks#50)

@x1B
Copy link
Member

x1B commented Apr 6, 2017

@jpommerening sure that we need a context mock? I would think an ideal axI18n mock would not even talk to the event bus. Instead, the test could call some API like .mockUpdateLocale( name, tag )?

@jpommerening
Copy link
Member Author

Good point, agree 💯

@x1B x1B added this to the v2.0.0 milestone Apr 6, 2017
@x1B x1B self-assigned this Apr 6, 2017
@x1B
Copy link
Member

x1B commented Apr 7, 2017

Implemented on master (v2.0.0).

BREAKING CHANGE

The API to createAxI18nMock of the laxar/laxar-widget-service-mocks library has changed. Previously, an axI18n-compatible object had to be passed in, effectively restricting use of the mock to the LaxarJS Mocks library (which will now need to be adjusted).

Now, an axI18n mock can be created…

  • without arguments
  • passing a mapping of locale topic to language tag as the first argument.
    Use when { default: 'en' } is not enough for testing
  • passing an AxContext-like object as the second argument (first argument may still be used, or set to an empty object). This should now be used by LaxarJS Mocks to share the axI18n eventBus with the remaining test

Also, the mock now exposes a method mockUpdateLocale to modify the languageTag of a locale topic after creation.

@x1B x1B closed this as completed Apr 7, 2017
x1B added a commit that referenced this issue Apr 7, 2017
x1B added a commit to LaxarJS/laxar-mocks that referenced this issue Apr 7, 2017
x1B added a commit to LaxarJS/laxar-mocks that referenced this issue Apr 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants