@genesislcap/foundation-testing 14.408.0 → 14.409.0-FUI-2495.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +5 -278
  2. package/package.json +5 -6
  3. package/docs/api/foundation-testing.componentcontext.container.md +0 -11
  4. package/docs/api/foundation-testing.componentcontext.designsystem.md +0 -11
  5. package/docs/api/foundation-testing.componentcontext.md +0 -91
  6. package/docs/api/foundation-testing.componentcontext.runcases.md +0 -11
  7. package/docs/api/foundation-testing.createcomponentsuite.md +0 -168
  8. package/docs/api/foundation-testing.createlogicsuite.md +0 -99
  9. package/docs/api/foundation-testing.delayedresolve.md +0 -80
  10. package/docs/api/foundation-testing.elementgetter.md +0 -12
  11. package/docs/api/foundation-testing.equal.md +0 -13
  12. package/docs/api/foundation-testing.expect.md +0 -13
  13. package/docs/api/foundation-testing.filterconditionally.md +0 -15
  14. package/docs/api/foundation-testing.fixture.connect.md +0 -21
  15. package/docs/api/foundation-testing.fixture.disconnect.md +0 -21
  16. package/docs/api/foundation-testing.fixture.document.md +0 -13
  17. package/docs/api/foundation-testing.fixture.element.md +0 -13
  18. package/docs/api/foundation-testing.fixture.md +0 -171
  19. package/docs/api/foundation-testing.fixture.parent.md +0 -18
  20. package/docs/api/foundation-testing.fixture.template.md +0 -13
  21. package/docs/api/foundation-testing.fixture.view.md +0 -13
  22. package/docs/api/foundation-testing.fixtureoptions.context.md +0 -13
  23. package/docs/api/foundation-testing.fixtureoptions.designsystem.md +0 -13
  24. package/docs/api/foundation-testing.fixtureoptions.document.md +0 -13
  25. package/docs/api/foundation-testing.fixtureoptions.md +0 -134
  26. package/docs/api/foundation-testing.fixtureoptions.parent.md +0 -13
  27. package/docs/api/foundation-testing.fixtureoptions.source.md +0 -13
  28. package/docs/api/foundation-testing.logger.md +0 -18
  29. package/docs/api/foundation-testing.logiccontext.md +0 -40
  30. package/docs/api/foundation-testing.logiccontext.runcases.md +0 -64
  31. package/docs/api/foundation-testing.md +0 -317
  32. package/docs/api/foundation-testing.resettestharness.md +0 -54
  33. package/docs/api/foundation-testing.restoretestharness.md +0 -54
  34. package/docs/api/foundation-testing.runcases.md +0 -12
  35. package/docs/api/foundation-testing.sinonwrapper.md +0 -17
  36. package/docs/api/foundation-testing.spiedfunctions.md +0 -15
  37. package/docs/api/foundation-testing.suitecallback.md +0 -15
  38. package/docs/api/foundation-testing.testspy.md +0 -66
  39. package/docs/api/foundation-testing.timeout.md +0 -99
  40. package/docs/api/foundation-testing.withtestharness.md +0 -17
  41. package/docs/api/index.md +0 -30
  42. package/docs/api-report.md.api.md +0 -143
package/README.md CHANGED
@@ -1,294 +1,21 @@
1
- # Genesis Foundation testing
1
+ # @genesislcap/foundation-testing
2
2
 
3
- [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)
4
- [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](https://www.typescriptlang.org/)
3
+ Documentation for this package is published on the Genesis docs site:
5
4
 
6
- `foundation-testing` provides shared unit and e2e testing functionality.
7
-
8
- ## Unit Testing
9
-
10
- The foundation-testing package is a comprehensive framework for implementing Unit Tests. Use it to ensure that your Genesis Web Application provides a seamless user experience by testing components, functions and user interactions across various scenarios.
11
-
12
- ### **Key Tools and Features:**
13
-
14
- - **Customizable Unit Test Suites**: Manage and create detailed test suites in the **tests/unit** folder, focusing on critical components and functions. These test suites are fully customizable by default, so you can cover all different parts of the application.
15
- - **Sinon integration**: Use Sinon.JS to incorporate test spies, stubs and mocks into your Unit Tests.
16
- - **Very lightweight**: The test framework provided by foundation-testing is very lightweight and contains [minimal dependencies](https://npm.anvaka.com/#/view/2d/uvu).
17
- - **Extremely performant**: Much faster than competing test runners, see [benchmarks](https://github.com/lukeed/uvu/tree/master#benchmarks).
18
- - **Individually executable test files**: You can keep your tests suites organized by splitting them into multiple files (optional).
19
- - **Browser-compatible**: You can easily run and debug your tests in a browser environment, which allows you to use browser developer tools.
20
-
21
- ### **Getting Started with Unit Testing:**
22
-
23
- - Define test suites in the **tests/unit** folder, targeting critical components and functions.
24
- - Use UVU for fast and lightweight Unit Testing.
25
- - Use Sinon.JS if you need spies, stubs or mocks.
26
- - Execute tests locally or on your CI pipeline, ensuring reliable and consistent outcomes.
27
-
28
- ## E2E Testing
29
-
30
- The foundation-testing package is a comprehensive framework for implementing End-to-End (E2E) testing. use it to ensure that your Genesis Web Application provides a seamless user experience by testing workflows and user interactions across various scenarios.
31
-
32
- ### **Key Tools and Features:**
33
-
34
- - **Customizable E2E scenarios**: Manage and create detailed test scenarios within the **tests/e2e** folder, focusing on critical user journeys. These scenarios are fully customizable by default, allowing for comprehensive coverage of different user paths and interactions.
35
- - **Playwright integration**: Use Playwright to automate browser actions, simulate user interactions, and verify that your application behaves as expected across different browsers. Playwright supports cross-browser testing, parallel test execution, and context isolation, allowing for robust and scalable E2E tests. Playwright can capture videos, screenshots, and other artifacts when a test fails, aiding in debugging and issue resolution.
36
- - **Lighthouse performance testing**: Integrate Lighthouse to measure and improve the performance, accessibility, SEO, and overall quality of your web applications. Use Lighthouse reports to track key performance metrics, such as load time, interactivity, and visual stability, and enforce performance budgets to maintain a high standard for user experience.
37
- - **Automated testing pipeline**: Integrate your E2E tests into a continuous integration (CI) pipeline, ensuring that every change to the codebase is thoroughly tested before deployment. This automation reduces the risk of bugs and ensures consistent test outcomes across different environments.
38
-
39
- ### **Getting Started with E2E Testing:**
40
-
41
- 1. **Creating and running E2E Tests**:
42
- - Define test scenarios in the **tests/e2e** folder, targeting critical user journeys and application functionalities.
43
- - Use Playwright for browser automation and Lighthouse for performance auditing within the same test suite.
44
- - Execute tests via your preferred test runner or CI pipeline, ensuring reliable and consistent outcomes.
45
- 2. **Using Playwright**:
46
- - Install and configure Playwright as part of your project dependencies. Follow the set-up guide provided by the foundation-testing package.
47
- - Write and run tests using the Playwright API to simulate real-world user interactions. These include clicking buttons, filling in forms, and navigating from page to page.
48
- 3. **Incorporating Lighthouse**:
49
- - Integrate Lighthouse into your E2E tests to run performance audits alongside functional tests.
50
- - Use the insights from Lighthouse reports to identify and address performance issues, optimizing your application for speed and user experience.
51
- 4. **Advanced features**:
52
- - **BDD Testing**: Write behavior-driven tests using `playwright-bdd`, making it easier to define test scenarios and expectations in a human-readable format.
53
- - **Cross-Browser Testing**: Use the Playwright cross-browser support to ensure your application works seamlessly across different browsers, including Chrome, Firefox, and WebKit.
54
- - **Visual Testing**: Use the Playwrights screenshot and visual comparison features to validate the consistency of your UI across different devices and resolutions.
55
- - **Performance Budgets**: Set performance thresholds using Lighthouse to maintain high performance standards, ensuring metrics like Time to Interactive (TTI) and First Contentful Paint (FCP) stay within acceptable limits.
56
-
57
- ## Test Organisation
58
-
59
- You can unit-test specific logic by adding a test file alongside the source file.
60
-
61
- ```ts
62
- logic.ts
63
- logic.test.ts
64
- ```
65
-
66
- If your test spans more than one file or is more of an end-to-end test, you may wish to add your test to your package's **/test** directory instead. An example structure might be:
67
-
68
- ```plaintext
69
- ├── src
70
- │ └── logic.ts
71
- │ └── logic.test.ts
72
- │ └── component.ts
73
- │ └── component.test.ts
74
- ├── test
75
- │ └── e2e
76
- │ └── baseline.e2e.ts
77
- │ └── unit
78
- │ └── baseline.test.ts
79
- ├── package.json
80
- └── playwright.config.ts
81
- ```
82
-
83
- The contents of your package's **playwright.config.ts** may include:
84
-
85
- ```ts
86
- export { configDefaults as default } from '@genesislcap/foundation-testing/e2e';
87
- ```
88
-
89
- If you need to customise configuration, you can do it as follows:
90
-
91
- ```ts
92
- import { configDefaults } from '@genesislcap/foundation-testing/e2e';
93
-
94
- export default {
95
- ...configDefaults,
96
- // Any custom configuration here e.g. disabling the web server:
97
- webServer: undefined,
98
- };
99
- ```
100
-
101
- If you need to customise JSDOM, you can create a **jsdom.setup.ts** file in your package directory:
102
-
103
- ```ts
104
- // custom code
105
- export * from '@genesislcap/foundation-testing/jsdom';
106
- ```
107
-
108
- ## Test scripts
109
-
110
- The test-related scripts to add to your package's **package.json** file may include:
111
-
112
- ```json
113
- "test": "genx test",
114
- "test:single": "genx test --match connect.test.ts",
115
- "test:single:browser": "genx test --browser --match connect.test.ts",
116
- "test:single:browser:raw-match": "genx test --browser --raw-match --match ./**/connect.test.ts",
117
- "test:select": "genx test --match '(connect|reconnectStrategy|kv).test.ts'",
118
- "test:select:browser": "genx test --browser --match '(connect|reconnectStrategy|kv).test.ts'",
119
- "test:glob": "genx test --match reconnectStrategy*.test.ts",
120
- "test:glob:browser": "genx test --browser --match reconnectStrategy*.test.ts",
121
- "test:coverage": "genx test --coverage",
122
- "test:coverage:browser": "genx test --coverage --browser",
123
- "test:e2e": "genx test --e2e",
124
- "test:e2e:debug": "genx test --e2e --debug",
125
- "test:e2e:ui": "genx test --e2e --interactive",
126
- "test:unit:browser": "genx test --browser",
127
- "test:unit:browser:watch": "genx test --browser --watch",
128
- "test:unit:watch": "genx test --watch",
129
- "test:debug": "genx test --debug"
130
- ```
131
-
132
- ## Testing logic
133
-
134
- The **logic.test.ts** usually uses `createLogicSuite`, which is used to test function output given certain input
135
- arguments. Based on user feedback, these arguments are now passed as an array by convention:
136
-
137
- ```ts
138
- // logic.test.ts
139
- import { createLogicSuite } from '@genesislcap/foundation-testing';
140
- import { myFunction } from './logic';
141
-
142
- const Suite = createLogicSuite('myFunction');
143
- Suite('myFunction should provide expected results', ({ runCases }) => {
144
- runCases(myFunction, [
145
- [['1'], true],
146
- [[123], true],
147
- [['60%'], true],
148
- [['$60'], false],
149
- [['1.1'], false],
150
- [[''], false],
151
- [[true], false],
152
- [[null], false],
153
- [[undefined], false],
154
- ]);
155
- });
156
-
157
- Suite.run();
158
- ```
159
-
160
- ## Testing components
161
-
162
- The **component.test.ts** or any test that directly or indirectly makes use of the DI uses `createComponentSuite`. Apart from setting up and tearing down your element fixture with a wrapping design system and DI container, this util also allows you to provide DI container mocks, which are required for certain testing flows.
163
-
164
- ```ts
165
- // component.test.ts
166
- import { Connect } from '@genesislcap/foundation-comms';
167
- import { ConnectMock } from '@genesislcap/foundation-comms/testing';
168
- import { assert, createComponentSuite, Registration } from '@genesislcap/foundation-testing';
169
- import { MyComponent } from './component';
170
-
171
- /**
172
- * As we're using tag name in the Suite, we hold a reference to avoid tree shaking.
173
- */
174
- MyComponent;
175
-
176
- /**
177
- * Create mock
178
- */
179
- const connectMock = new ConnectMock();
180
- connectMock.nextMetadata = {
181
- FIELD: [
182
- {
183
- NAME: 'foo',
184
- TYPE: 'bar',
185
- },
186
- ],
187
- };
188
-
189
- /**
190
- * Resister mock instance
191
- */
192
- const mocks = [Registration.instance(Connect, connectMock)];
193
-
194
- const Suite = createComponentSuite<MyComponent>(
195
- 'MyComponent',
196
- 'my-component', // < or () => myComponent() if your component is composeable
197
- null,
198
- mocks,
199
- );
200
-
201
- Suite('Can be created in the DOM', async ({ element }) => {
202
- assert.ok(element);
203
- });
204
-
205
- Suite('Connect is mocked in the container', async ({ container }) => {
206
- const serviceMock = container.get(Connect);
207
- assert.instance(serviceMock, ConnectMock);
208
- });
209
-
210
- Suite('Attr changes update internals as expected', async ({ element }) => {
211
- element.setAttribute('resource-name', 'ALL_USERS');
212
- assert.match(element.optionsHash, /ALL_USERS/);
213
- element.setAttribute('order-by', 'USERNAME');
214
- assert.match(element.optionsHash, /USERNAME/);
215
- });
216
-
217
- Suite('Connect.getMetadata returns expected nextMetadata', async ({ container }) => {
218
- const serviceMock = container.get(Connect) as ConnectMock;
219
- /**
220
- * Assert base case
221
- */
222
- let serviceMeta = await serviceMock.getMetadata('someResource');
223
- assert.is(serviceMeta.FIELD[0].NAME, 'foo');
224
- /**
225
- * Apply next and assert
226
- */
227
- const metadata = {
228
- FIELD: [
229
- {
230
- NAME: 'hello',
231
- TYPE: 'world',
232
- },
233
- ],
234
- };
235
- serviceMock.nextMetadata = {
236
- ...metadata,
237
- };
238
- serviceMeta = await serviceMock.getMetadata('someResource');
239
- assert.equal(serviceMeta, {
240
- ...metadata,
241
- });
242
- // TODO: Trigger and cross check component reactions to underlying data changes
243
- });
244
-
245
- Suite.run();
246
- ```
247
-
248
- ## Testing E2E
249
-
250
- The **baseline.e2e.ts** uses `playwright`; test cases have access to the fixtures provided during set-up.
251
-
252
- ```ts
253
- import { test, expect } from '@genesislcap/foundation-testing/e2e';
254
-
255
- test('baseline test', async ({ page }) => {
256
- await page.goto('https://playwright.dev/');
257
- const name = await page.innerText('.navbar__title');
258
- expect(name).toBe('Playwright');
259
- });
260
- ```
261
-
262
- _We will be adding more details on E2E in future updates._
5
+ **Docs: [Testing](https://docs.genesis.global/docs/develop/client-capabilities/testing/)**
263
6
 
264
7
  ## Installation
265
8
 
266
- To enable this module in your application, follow the steps below.
267
-
268
- 1. Add `@genesislcap/foundation-testing` as a dependency in your `package.json` file. Whenever you change the dependencies of your project, ensure you run the `$ npm run bootstrap` command again. You can find more information in the [package.json basics](https://learn.genesis.global/secure/web/basics/package-json-basics/) page.
9
+ Add the package to your `package.json` dependencies. After changing dependencies, run `npm run bootstrap` (or your project's equivalent). See [package.json basics](https://learn.genesis.global/secure/web/basics/package-json-basics/) for more information.
269
10
 
270
11
  ```json
271
12
  {
272
13
  "dependencies": {
273
14
  "@genesislcap/foundation-testing": "latest"
274
- },
15
+ }
275
16
  }
276
17
  ```
277
18
 
278
- ### **Unit Testing Resources and Further Documentation:**
279
-
280
- - [UVU](ttps://github.com/lukeed/uvu)
281
- - [Sinon.JS](https://sinonjs.org/releases/v18/)
282
-
283
- ### **E2E Resources and Further Documentation:**
284
-
285
- - [foundation-testing](https://github.com/genesislcap/foundation-ui/tree/master/packages/foundation/foundation-testing)
286
- - [Playwright Documentation](https://playwright.dev/)
287
- - [playwright-bdd](https://github.com/vitalets/playwright-bdd)
288
- - [Lighthouse Documentation](https://developers.google.com/web/tools/lighthouse)
289
-
290
- ## [API Docs](./docs/api/index.md)
291
-
292
19
  ## License
293
20
 
294
21
  Note: this project provides front-end dependencies and uses licensed components listed in the next section; thus, licenses for those components are required during development. Contact [Genesis Global](https://genesis.global/contact-us/) for more details.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/foundation-testing",
3
3
  "description": "Genesis Foundation Testing",
4
- "version": "14.408.0",
4
+ "version": "14.409.0-FUI-2495.2",
5
5
  "sideEffects": false,
6
6
  "license": "SEE LICENSE IN license.txt",
7
7
  "main": "dist/esm/index.js",
@@ -54,11 +54,10 @@
54
54
  },
55
55
  "scripts": {
56
56
  "api:extract": "api-extractor run --local",
57
- "api:document": "api-documenter markdown -i dist -o docs/api",
58
- "build": "npm run clean && tsc -b ./tsconfig.json && tsc -b ./tsconfig.cjs.json && npm run api:extract && npm run api:document",
57
+ "build": "npm run clean && tsc -b ./tsconfig.json && tsc -b ./tsconfig.cjs.json && npm run api:extract",
59
58
  "circular": "npx -y madge --extensions ts --circular ./src",
60
59
  "clean": "rimraf dist temp tsconfig.tsbuildinfo",
61
- "dev": "tsc -b ./tsconfig.json -w",
60
+ "dev": "genx dev -b ts",
62
61
  "test": "uvu -r tsx/cjs -r ./src/jsdom/setup.ts . test.ts",
63
62
  "lint": "genx lint --profile",
64
63
  "lint:fix": "genx lint --fix"
@@ -76,7 +75,7 @@
76
75
  "tsx": "^4.7.0"
77
76
  },
78
77
  "dependencies": {
79
- "@genesislcap/foundation-logger": "14.408.0",
78
+ "@genesislcap/foundation-logger": "14.409.0-FUI-2495.2",
80
79
  "@microsoft/fast-element": "1.14.0",
81
80
  "@microsoft/fast-foundation": "2.50.0",
82
81
  "@playwright/test": "^1.54.2",
@@ -96,5 +95,5 @@
96
95
  "publishConfig": {
97
96
  "access": "public"
98
97
  },
99
- "gitHead": "26b08831fd001b4ee95c8a0d3364a18c0ec4005b"
98
+ "gitHead": "1fcaf08e9b7559024b25dc6ccc27e3bc62f1512b"
100
99
  }
@@ -1,11 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-testing](./foundation-testing.md) &gt; [ComponentContext](./foundation-testing.componentcontext.md) &gt; [container](./foundation-testing.componentcontext.container.md)
4
-
5
- ## ComponentContext.container property
6
-
7
- **Signature:**
8
-
9
- ```typescript
10
- container: Container;
11
- ```
@@ -1,11 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-testing](./foundation-testing.md) &gt; [ComponentContext](./foundation-testing.componentcontext.md) &gt; [designSystem](./foundation-testing.componentcontext.designsystem.md)
4
-
5
- ## ComponentContext.designSystem property
6
-
7
- **Signature:**
8
-
9
- ```typescript
10
- designSystem: DesignSystem;
11
- ```
@@ -1,91 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-testing](./foundation-testing.md) &gt; [ComponentContext](./foundation-testing.componentcontext.md)
4
-
5
- ## ComponentContext interface
6
-
7
- Component suite context interface
8
-
9
- **Signature:**
10
-
11
- ```typescript
12
- export interface ComponentContext<TElement = HTMLElement> extends Pick<Fixture<TElement>, 'element' | 'disconnect'>
13
- ```
14
- **Extends:** Pick&lt;[Fixture](./foundation-testing.fixture.md)<!-- -->&lt;TElement&gt;, 'element' \| 'disconnect'&gt;
15
-
16
- ## Properties
17
-
18
- <table><thead><tr><th>
19
-
20
- Property
21
-
22
-
23
- </th><th>
24
-
25
- Modifiers
26
-
27
-
28
- </th><th>
29
-
30
- Type
31
-
32
-
33
- </th><th>
34
-
35
- Description
36
-
37
-
38
- </th></tr></thead>
39
- <tbody><tr><td>
40
-
41
- [container](./foundation-testing.componentcontext.container.md)
42
-
43
-
44
- </td><td>
45
-
46
-
47
- </td><td>
48
-
49
- Container
50
-
51
-
52
- </td><td>
53
-
54
-
55
- </td></tr>
56
- <tr><td>
57
-
58
- [designSystem](./foundation-testing.componentcontext.designsystem.md)
59
-
60
-
61
- </td><td>
62
-
63
-
64
- </td><td>
65
-
66
- DesignSystem
67
-
68
-
69
- </td><td>
70
-
71
-
72
- </td></tr>
73
- <tr><td>
74
-
75
- [runCases](./foundation-testing.componentcontext.runcases.md)
76
-
77
-
78
- </td><td>
79
-
80
-
81
- </td><td>
82
-
83
- [RunCases](./foundation-testing.runcases.md)
84
-
85
-
86
- </td><td>
87
-
88
-
89
- </td></tr>
90
- </tbody></table>
91
-
@@ -1,11 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-testing](./foundation-testing.md) &gt; [ComponentContext](./foundation-testing.componentcontext.md) &gt; [runCases](./foundation-testing.componentcontext.runcases.md)
4
-
5
- ## ComponentContext.runCases property
6
-
7
- **Signature:**
8
-
9
- ```typescript
10
- runCases: RunCases;
11
- ```
@@ -1,168 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-testing](./foundation-testing.md) &gt; [createComponentSuite](./foundation-testing.createcomponentsuite.md)
4
-
5
- ## createComponentSuite() function
6
-
7
- Create component test suite.
8
-
9
- **Signature:**
10
-
11
- ```typescript
12
- export declare function createComponentSuite<TElement = HTMLElement>(title: string, elementNameOrGetter: string | ElementGetter, context?: ComponentContext<TElement>, registrations?: Registration<any>[]): uvu.Test<ComponentContext<TElement>>;
13
- ```
14
-
15
- ## Parameters
16
-
17
- <table><thead><tr><th>
18
-
19
- Parameter
20
-
21
-
22
- </th><th>
23
-
24
- Type
25
-
26
-
27
- </th><th>
28
-
29
- Description
30
-
31
-
32
- </th></tr></thead>
33
- <tbody><tr><td>
34
-
35
- title
36
-
37
-
38
- </td><td>
39
-
40
- string
41
-
42
-
43
- </td><td>
44
-
45
- Title of the test suite
46
-
47
-
48
- </td></tr>
49
- <tr><td>
50
-
51
- elementNameOrGetter
52
-
53
-
54
- </td><td>
55
-
56
- string \| [ElementGetter](./foundation-testing.elementgetter.md)
57
-
58
-
59
- </td><td>
60
-
61
- Element tag name or getter which is used to create the element within the fixture
62
-
63
-
64
- </td></tr>
65
- <tr><td>
66
-
67
- context
68
-
69
-
70
- </td><td>
71
-
72
- [ComponentContext](./foundation-testing.componentcontext.md)<!-- -->&lt;TElement&gt;
73
-
74
-
75
- </td><td>
76
-
77
- _(Optional)_ Optional component context [ComponentContext](./foundation-testing.componentcontext.md)
78
-
79
-
80
- </td></tr>
81
- <tr><td>
82
-
83
- registrations
84
-
85
-
86
- </td><td>
87
-
88
- Registration&lt;any&gt;\[\]
89
-
90
-
91
- </td><td>
92
-
93
- _(Optional)_ Optional array of DI container registrations
94
-
95
-
96
- </td></tr>
97
- </tbody></table>
98
-
99
- **Returns:**
100
-
101
- uvu.Test&lt;[ComponentContext](./foundation-testing.componentcontext.md)<!-- -->&lt;TElement&gt;&gt;
102
-
103
- The test suite
104
-
105
- ## Remarks
106
-
107
- Used to test function output given certain input arguments.
108
-
109
- ## Example 1
110
-
111
- Simple suite using the tag name of the component.
112
-
113
- ```ts
114
- import { createComponentSuite } from '@genesislcap/foundation-testing';
115
- import { Component } from './component';
116
- Component; // < As we're using tag name in the Suite, we hold a reference to avoid tree shaking.
117
- const Suite = createComponentSuite<Component>('Component', 'my-component');
118
- // test cases...
119
- Suite.run();
120
- ```
121
-
122
- ## Example 2
123
-
124
- Mocking a DI dependency for a composable component.
125
-
126
- ```ts
127
- const connectMock = new ConnectMock();
128
- const mocks = [Registration.instance(Connect, connectMock)];
129
- const Suite = createComponentSuite<ConnectionIndicator>('ConnectionIndicator Component', () => connectionIndicator(), null, mocks);
130
- // test cases...
131
- Suite.run();
132
- ```
133
-
134
- ## Example 3
135
-
136
- An element will be required to test anything that directly or in-directly makes use of the DI container, for example, a service that can be injected into components, or has its own injected dependencies.
137
-
138
- ```ts
139
- import { Service } from './service';
140
- @customElement({
141
- name: 'test-element',
142
- template: html`<slot></slot>`,
143
- })
144
- class TestElement extends FASTElement {}
145
- const mocks = [...];
146
- const Suite = createComponentSuite<TestElement>('Service', 'test-element', null, mocks);
147
- // test cases...
148
- Suite.run();
149
- ```
150
- Importing the service should invoke the Service's DI registration, so in your test cases you can simply query the container to get a reference to your service.
151
-
152
- ```ts
153
- Suite('Service.x does something expected', async ({ container }) => {
154
- const myService = container.get(Service);
155
- // assert
156
- });
157
- ```
158
- You can optionally add the service to the test element for lookup convenience, but this is not required.
159
-
160
- ```ts
161
- class TestElement extends FASTElement {
162
- @Service service: Service;
163
- }
164
- Suite('Element has service injected', async ({ element }) => {
165
- assert.ok(element.service);
166
- });
167
- ```
168
-