Component SDK - Getting Started
TopicTopics usually cover more ground than other articles.
Author:
Fluent Commerce
Changed on:
1 July 2024
Author:
Fluent Commerce
Changed on:
1 July 2024
Author:
Fluent Commerce
Changed on:
1 July 2024
`mystique-plugin-acme``$ git init``$ yarn install``$ yarn start``{ "src": "http://myhost.com/myplugin/bundle.js" }`)`{ "src": "http://myhost.com/myplugin/" }`)`version.json` file at the root of the specified folder and take the bundle name from there.The `version.json` is retrieved with a `v` parameter of the current date rounded to the nearest 10 seconds to avoid stale cache hits (e.g. `http://myhost.com/myplugin/version.json?v=1628209170000`).Where the hash value would come from a Webpack `contenthash` (see Webpack Caching) or equivalent.This gives SDK developers the ability to:`Jest.spyOn` to swap out the implementation with something that returns what your component is expectingFor example, a simple version of mocking the `useI18n()` hook might look like this:Consult the hook interface documentation in the `@types` folder of your SDK project for more details on hook signatures and response types.1{
2 "plugins":[{ "src": "http://localhost:3001/bundle.js" }],
3 "routes": [
4 { "path":"hello", "component":"fc.hello" }
5 ]
6}1{
2 "bundle": "bundle.8d2c4b9aebdc9b502b32.js"
3}1import * as UseI18n from 'mystique/hooks/useI18n';
2
3const i18nValues: any = {
4 'fc.test.a': 'Test Value 1',
5};
6
7describe('Tests that require translation of strings', () => {
8
9 beforeEach(() => {
10 jest.spyOn(UseI18n, 'useI18n').mockImplementation(() => ({
11 translate: (key: string) => i18nValues[key]
12 }));
13 });
14
15 // tests go here...
16});