@genesislcap/foundation-testing 14.30.3 → 14.31.0

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.
@@ -1,384 +0,0 @@
1
- import * as assert from 'uvu/assert';
2
- import { Constructable } from '@microsoft/fast-element';
3
- import { Container } from '@microsoft/fast-foundation';
4
- import { DesignSystem } from '@microsoft/fast-foundation';
5
- import { ExecutionContext } from '@microsoft/fast-element';
6
- import type { FoundationElement } from '@microsoft/fast-foundation';
7
- import { FoundationElementDefinition } from '@microsoft/fast-foundation';
8
- import { FoundationElementRegistry } from '@microsoft/fast-foundation';
9
- import { HTMLView } from '@microsoft/fast-element';
10
- import { Logger } from '@genesislcap/foundation-utils';
11
- import { Registration } from '@microsoft/fast-foundation';
12
- import { default as sinon_2 } from 'sinon';
13
- import { suite } from 'uvu';
14
- import { test } from 'uvu';
15
- import { uvu } from 'uvu';
16
- import { ViewTemplate } from '@microsoft/fast-element';
17
-
18
- export { assert }
19
-
20
- /**
21
- * Component suite context interface
22
- * @public
23
- */
24
- export declare interface ComponentContext<TElement = HTMLElement> extends Pick<Fixture<TElement>, 'element' | 'disconnect'> {
25
- designSystem: DesignSystem;
26
- container: Container;
27
- runCases: RunCases;
28
- }
29
-
30
- /**
31
- * Create component test suite.
32
- *
33
- * @example
34
- * Simple suite using the tag name of the component.
35
- * ```ts
36
- * import { createComponentSuite } from '@genesislcap/foundation-testing';
37
- * import { Component } from './component';
38
- * Component; // < As we're using tag name in the Suite, we hold a reference to avoid tree shaking.
39
- * const Suite = createComponentSuite<Component>('Component', 'my-component');
40
- * // test cases...
41
- * Suite.run();
42
- * ```
43
- *
44
- * @example
45
- * Mocking a DI dependency for a composable component.
46
- * ```ts
47
- * const connectMock = new ConnectMock();
48
- * const mocks = [Registration.instance(Connect, connectMock)];
49
- * const Suite = createComponentSuite<ConnectionIndicator>('ConnectionIndicator Component', () => connectionIndicator(), null, mocks);
50
- * // test cases...
51
- * Suite.run();
52
- * ```
53
- *
54
- * @example
55
- * An element will be required to test anything that directly or in-directly makes use of the DI container, for example,
56
- * a service that can be injected into components, or has its own injected dependencies.
57
- * ```ts
58
- * import { Service } from './service';
59
- * @customElement({
60
- * name: 'test-element',
61
- * template: html`<slot></slot>`,
62
- * })
63
- * class TestElement extends FASTElement {}
64
- * const mocks = [...];
65
- * const Suite = createComponentSuite<TestElement>('Service', 'test-element', null, mocks);
66
- * // test cases...
67
- * Suite.run();
68
- * ```
69
- *
70
- * Importing the service should invoke the Service's DI registration, so in your test cases you can simply query the
71
- * container to get a reference to your service.
72
- * ```ts
73
- * Suite('Service.x does something expected', async ({ container }) => {
74
- * const myService = container.get(Service);
75
- * // assert
76
- * });
77
- * ```
78
- *
79
- * You can optionally add the service to the test element for lookup convenience, but this is not required.
80
- * ```ts
81
- * class TestElement extends FASTElement {
82
- * @Service service: Service;
83
- * }
84
- * Suite('Element has service injected', async ({ element }) => {
85
- * assert.ok(element.service);
86
- * });
87
- * ```
88
- *
89
- * @typeParam TElement - The element interface.
90
- * @param title - Title of the test suite
91
- * @param elementNameOrGetter - Element tag name or getter which is used to create the element within the fixture
92
- * @param context - Optional component context {@link ComponentContext}
93
- * @param registrations - Optional array of DI container registrations
94
- * @returns The test suite
95
- * @public
96
- * @remarks
97
- * Used to test function output given certain input arguments.
98
- */
99
- export declare function createComponentSuite<TElement = HTMLElement>(title: string, elementNameOrGetter: string | ElementGetter, context?: ComponentContext<TElement>, registrations?: Registration<any>[]): uvu.Test<ComponentContext<TElement>>;
100
-
101
- /**
102
- * Create logic test suite.
103
- *
104
- * @example
105
- * ```ts
106
- * import { createLogicSuite } from '@genesislcap/foundation-testing';
107
- * import { myFunction } from './logic';
108
- * const Suite = createLogicSuite('myFunction');
109
- * Suite('myFunction should provide expected results', ({ runCases }) => {
110
- * runCases(myFunction, [
111
- * [['1'], true],
112
- * [[123], true],
113
- * [['60%'], true],
114
- * [['$60'], false],
115
- * [['1.1'], false],
116
- * [[''], false],
117
- * [[true], false],
118
- * [[null], false],
119
- * [[undefined], false],
120
- * ]);
121
- * });
122
- * Suite.run();
123
- * ```
124
- *
125
- * @typeParam TContext - The context interface.
126
- * @param title - Title of the test suite
127
- * @param context - Optional context which extends {@link LogicContext}
128
- * @returns The test suite
129
- * @public
130
- * @remarks
131
- * Used to test function output given certain input arguments.
132
- */
133
- export declare function createLogicSuite<TContext = LogicContext>(title: string, context?: TContext): uvu.Test<TContext>;
134
-
135
- /**
136
- * @public
137
- */
138
- export declare type ElementGetter = () => FoundationElementRegistry<FoundationElementDefinition, FoundationElement>;
139
-
140
- /**
141
- * Expects that the type parameter X is equal to Y, returning true or false
142
- * @public
143
- */
144
- export declare type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
145
-
146
- /**
147
- * Expects that the type parameter T resolves to true, or will be a typescript error
148
- * @public
149
- */
150
- export declare type Expect<T extends true> = T;
151
-
152
- /**
153
- * Filters out key/value pairs from an object where they value does not match a condition
154
- * @public
155
- */
156
- export declare type FilterConditionally<Source, Condition> = Pick<Source, {
157
- [K in keyof Source]: Source[K] extends Condition ? K : never;
158
- }[keyof Source]>;
159
-
160
- /**
161
- * Unit test fixture.
162
- * @public
163
- */
164
- export declare interface Fixture<TElement = HTMLElement> {
165
- /**
166
- * The document the fixture is running in.
167
- */
168
- document: Document;
169
- /**
170
- * The template the fixture was created from.
171
- */
172
- template: ViewTemplate;
173
- /**
174
- * The view that was created from the fixture's template.
175
- */
176
- view: HTMLView;
177
- /**
178
- * The parent element that the view was appended to.
179
- * @remarks
180
- * This element will be appended to the DOM only
181
- * after {@link Fixture.connect} has been called.
182
- */
183
- parent: HTMLElement;
184
- /**
185
- * The first element in the {@link Fixture.view}.
186
- */
187
- element: TElement;
188
- /**
189
- * Adds the {@link Fixture.parent} to the DOM, causing the
190
- * connect lifecycle to begin.
191
- * @remarks
192
- * Yields control to the caller one Microtask later, in order to
193
- * ensure that the DOM has settled.
194
- */
195
- connect(): Promise<void>;
196
- /**
197
- * Removes the {@link Fixture.parent} from the DOM, causing the
198
- * disconnect lifecycle to begin.
199
- * @remarks
200
- * Yields control to the caller one Microtask later, in order to
201
- * ensure that the DOM has settled.
202
- */
203
- disconnect(): Promise<void>;
204
- }
205
-
206
- /**
207
- * Creates a test fixture suitable for testing custom elements, templates, and bindings.
208
- * @param templateNameOrRegistry - An HTML template or single element name to create the fixture for.
209
- * @param options - Enables customizing fixture creation behavior.
210
- * @returns A promise of the test fixture {@link Fixture}.
211
- *
212
- * @public
213
- * @remarks
214
- * Yields control to the caller one Microtask later, in order to
215
- * ensure that the DOM has settled. This has changed in the latest version of FAST!
216
- */
217
- export declare function fixture<TElement = HTMLElement>(templateNameOrRegistry: ViewTemplate | string | FoundationElementRegistry<FoundationElementDefinition, Constructable<TElement>> | [
218
- FoundationElementRegistry<FoundationElementDefinition, Constructable<TElement>>,
219
- ...FoundationElementRegistry<FoundationElementDefinition, Constructable>[]
220
- ], options?: FixtureOptions): Promise<Fixture<TElement>>;
221
-
222
- /**
223
- * Options used to customize the creation of the unit test fixture.
224
- * @public
225
- */
226
- export declare interface FixtureOptions {
227
- /**
228
- * The document to run the fixture in.
229
- * @defaultValue `globalThis.document`
230
- */
231
- document?: Document;
232
- /**
233
- * The parent element to append the fixture to.
234
- * @defaultValue An instance of `HTMLDivElement`.
235
- */
236
- parent?: HTMLElement;
237
- /**
238
- * The data source to bind the HTML to.
239
- * @defaultValue An empty object.
240
- */
241
- source?: any;
242
- /**
243
- * The execution context to use during binding.
244
- * @defaultValue {@link @microsoft/fast-element#defaultExecutionContext}
245
- */
246
- context?: ExecutionContext;
247
- /**
248
- * A pre-configured design system instance used in setting up the fixture.
249
- */
250
- designSystem?: DesignSystem;
251
- }
252
-
253
- /**
254
- * Test logger
255
- * @public
256
- * @remarks
257
- * Exported so you can set log levels differently across packages when needed.
258
- */
259
- export declare const logger: Logger;
260
-
261
- /**
262
- * Logic suite context interface
263
- * @public
264
- */
265
- export declare interface LogicContext {
266
- /**
267
- * @privateRemarks
268
- * Not hardening the typing on this to RunCases until get a feel for usages.
269
- */
270
- runCases?(fn: (value: any) => any, cases: [any, any, assert.Message?][]): void;
271
- }
272
-
273
- export { Registration }
274
-
275
- /**
276
- * Resets the history of the spied functions on the objects so previous running tests
277
- * don't affect the current test.
278
- * Must be called at the end of every test even if not asserting on the spies.
279
- * @param wrapper - `WithTestHarness<T>` object to reset
280
- * @public
281
- */
282
- export declare function resetTestHarness<T>(wrapper: WithTestHarness<T>): void;
283
-
284
- /**
285
- * Restores the spied functions back to the original functions without the spies.
286
- * @param wrapper - `WithTestHarness<T>` object to restore
287
- * @public
288
- */
289
- export declare function restoreTestHarness<T>(wrapper: WithTestHarness<T>): void;
290
-
291
- /**
292
- * @public
293
- */
294
- export declare type RunCases = (fn: (...args: unknown[]) => unknown, cases: [unknown[], unknown, string?][], assertion?: (...args: unknown[]) => void) => void;
295
-
296
- /**
297
- * Assert a set of test cases.
298
- * @param fn - The function to test.
299
- * @param cases - An array of test cases to run against the function.
300
- * @param assertion - Optional uvu assertion method, defaults to assert.equal.
301
- * @public
302
- * @remarks
303
- * This is available as part of the suite context, but can also be run standalone.
304
- */
305
- export declare function runCases(fn: (...args: unknown[]) => unknown, cases: [unknown[], unknown, string?][], assertion?: (...args: unknown[]) => void): void;
306
-
307
- /**
308
- * Crates an object with a key value pair for each spied function
309
- * where the key is the function name and the value is the sinon wrapped
310
- * spy function
311
- * @public
312
- * @typeParam T - object with keys where values are functions
313
- */
314
- export declare type SinonWrapper<T extends {
315
- [K in keyof T]: (...args: any) => any;
316
- }> = {
317
- [K in keyof T]: sinon_2.SinonSpy<Parameters<T[K]>, ReturnType<T[K]>>;
318
- };
319
-
320
- /**
321
- * Filters out all key/value pairs which are not functions, and omits the constructor
322
- * @public
323
- */
324
- export declare type SpiedFunctions<T> = Omit<FilterConditionally<T, (...args: any[]) => any>, 'constructor'>;
325
-
326
- export { suite }
327
-
328
- /**
329
- * Defines the Generic type for a test Suite `T` the callback function
330
- * required to assert on type `T`.
331
- * @typeParam T - the top level class we are testing
332
- * @public
333
- */
334
- export declare type SuiteCallback<T> = uvu.Callback<ComponentContext<T>>;
335
-
336
- export { test }
337
-
338
- /**
339
- * Decorator: Used on a test harness class based on a `FoundationElement` to give it extra functionality
340
- * which can be used during testing. *Important* this is to be used on a parent element compared to
341
- * the element under test.
342
- *
343
- *
344
- * @remarks
345
- * Access the test functionality using the type with {@link WithTestHarness}
346
- *
347
- * Reset after each test with {@link resetTestHarness}
348
- *
349
- * @example
350
- *
351
- * // Testing the first function call
352
- * async (\{ element \}) =\> \{
353
- *
354
- assert.ok(
355
- element.layout.addItemFromChild.calledWith(\{
356
- type: 'component',
357
- componentType: 'test',
358
- title: `Item test`,
359
- reorderEnabled: true,
360
- isClosable: false,
361
- size: undefined,
362
- \})
363
- );
364
- *
365
- * // Reset the tester at the end of every test even if you don't assert on any of it!
366
- * resetTestHarness(element.layout);
367
- * \}
368
- *
369
- * @public
370
- */
371
- export declare function testSpy(constructor: Function): void;
372
-
373
- export { uvu }
374
-
375
- /**
376
- * Type can be used to inform Typescript the object decorated with {@link testSpy} has function
377
- * spies which can be interacted upon their normal function reference
378
- * @public
379
- */
380
- export declare type WithTestHarness<T extends {
381
- [k in keyof T]: any;
382
- }> = T & SinonWrapper<SpiedFunctions<T>>;
383
-
384
- export { }
@@ -1,11 +0,0 @@
1
- // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
- // It should be published with your NPM package. It should not be tracked by Git.
3
- {
4
- "tsdocVersion": "0.12",
5
- "toolPackages": [
6
- {
7
- "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.34.4"
9
- }
10
- ]
11
- }