@leaflink/dom-testing-utils 1.2.1 → 2.0.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.
- package/README.md +50 -12
- package/dist/index.d.ts +24 -7
- package/dist/index.js +70 -14
- package/dist/index.js.map +1 -1
- package/dist/index.spec.js +37 -3
- package/dist/index.spec.js.map +1 -1
- package/dist/setup-env.js +4 -4
- package/dist/setup-env.js.map +1 -1
- package/package.json +36 -24
package/README.md
CHANGED
|
@@ -13,12 +13,15 @@
|
|
|
13
13
|
|
|
14
14
|
- [Installation](#installation)
|
|
15
15
|
- [Usage](#usage)
|
|
16
|
-
- [Global setup](#global-setup)
|
|
17
16
|
- [Setup file](#setup-file)
|
|
17
|
+
- [Global setup](#global-setup)
|
|
18
|
+
- [Utilities](#utilities)
|
|
18
19
|
- [`cleanupNoty`](#cleanupnoty)
|
|
19
20
|
- [`waitForLoadingToFinish`](#waitforloadingtofinish)
|
|
20
21
|
- [`cleanupDropdowns`](#cleanupdropdowns)
|
|
21
22
|
- [`assertAndDismissNoty`](#assertanddismissnoty)
|
|
23
|
+
- [`getByDescriptionTerm`](#getbydescriptionterm)
|
|
24
|
+
- [`getAllByDescriptionTerm`](#getallbydescriptionterm)
|
|
22
25
|
- [`createFixtureGenerator`](#createfixturegenerator)
|
|
23
26
|
- [Mocking API Endpoints](#mocking-api-endpoints)
|
|
24
27
|
|
|
@@ -32,7 +35,7 @@ npm install --save-dev @leaflink/dom-testing-utils
|
|
|
32
35
|
|
|
33
36
|
## Usage
|
|
34
37
|
|
|
35
|
-
In your
|
|
38
|
+
In your test files you can import utility functions.
|
|
36
39
|
|
|
37
40
|
```ts
|
|
38
41
|
import {
|
|
@@ -48,27 +51,41 @@ it('...', () => {
|
|
|
48
51
|
});
|
|
49
52
|
```
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
### Setup file
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
Import `@leaflink/dom-testing-utils/setup-env` once (for instance in your tests setup file) and you're good to go:
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
> **Note:** `@testing-library/jest-dom` is auto-imported from `@leaflink/dom-testing-utils` so you don't have to.
|
|
56
59
|
|
|
57
|
-
```
|
|
58
|
-
|
|
60
|
+
```ts
|
|
61
|
+
// In your own setup-env.ts (or any other name)
|
|
62
|
+
import '@leaflink/dom-testing-utils/setup-env'
|
|
63
|
+
// DON'T import `@testing-library/jest-dom` is auto imported from dom-testing-utils
|
|
64
|
+
|
|
65
|
+
// In vite.config.ts add (if you haven't already)
|
|
66
|
+
setupFiles: ['tests/setup-env.js'],
|
|
67
|
+
|
|
68
|
+
// In jest.config.js add (if you haven't already)
|
|
69
|
+
setupFilesAfterEnv: ['<rootDir>/tests/setup-env.js']
|
|
59
70
|
```
|
|
60
71
|
|
|
61
|
-
This will run once
|
|
72
|
+
This will be run once before *each* test file. See <https://vitest.dev/config/#setupfiles>.
|
|
62
73
|
|
|
63
|
-
###
|
|
74
|
+
### Global setup
|
|
64
75
|
|
|
65
|
-
Add the following
|
|
76
|
+
Add the following import to your test config:
|
|
66
77
|
|
|
67
78
|
```js
|
|
68
|
-
|
|
79
|
+
// In vite.config.ts add
|
|
80
|
+
globalSetup: ['node_modules/@leaflink/dom-testing-utils/dist/global-setup.js'],
|
|
81
|
+
|
|
82
|
+
// In jest.config.js add
|
|
83
|
+
globalSetup: ['<rootDir>/node_modules/@leaflink/dom-testing-utils/dist/global-setup.js']
|
|
69
84
|
```
|
|
70
85
|
|
|
71
|
-
This will
|
|
86
|
+
This will run once *before everything*. See <https://vitest.dev/config/#globalsetup>.
|
|
87
|
+
|
|
88
|
+
## Utilities
|
|
72
89
|
|
|
73
90
|
### `cleanupNoty`
|
|
74
91
|
|
|
@@ -108,6 +125,27 @@ Helper to assert and manually dismiss a notification. This is useful in scenari
|
|
|
108
125
|
|
|
109
126
|
**Returns**: `void`
|
|
110
127
|
|
|
128
|
+
### `getByDescriptionTerm`
|
|
129
|
+
|
|
130
|
+
Finds the first HTML element with the role "definition" (DD) that matches the specified text for the description term.
|
|
131
|
+
|
|
132
|
+
| **Parameters** | **Type** | **Default** | **Summary** |
|
|
133
|
+
| ----------- | ----------- | ----------- |----------- |
|
|
134
|
+
| text | `string \| RegExp` | *Required* | Expected description term text or regex |
|
|
135
|
+
|
|
136
|
+
**Returns**: `HTMLElement | undefined` - The first matching description detail element or undefined if no match is found.
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
### `getAllByDescriptionTerm`
|
|
140
|
+
|
|
141
|
+
Queries and returns an array of HTML elements with the role "definition" (DD) that matches the specified text of a description term.
|
|
142
|
+
|
|
143
|
+
| **Parameters** | **Type** | **Default** | **Summary** |
|
|
144
|
+
| ----------- | ----------- | ----------- |----------- |
|
|
145
|
+
| textMatch | `string \| RegExp` | *Required* | The text to match within the HTML elements. It can be a string or a regular expression. |
|
|
146
|
+
|
|
147
|
+
**Returns**: `HTMLElement[]` - An array of HTML description detail elements that match the given text.
|
|
148
|
+
|
|
111
149
|
### `createFixtureGenerator`
|
|
112
150
|
|
|
113
151
|
Higher order function that takes a method whose responsibility is to create a **single** data fixture object and returns a new generator function that allows you to create 1 or more of those fixtures. Fixture generator function that's returned supports passing optional `num` and `overrides` params.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createMockApiUtils, RestMethod } from
|
|
1
|
+
import { createMockApiUtils, RestMethod } from './api/mockEndpoints.js';
|
|
2
2
|
/**
|
|
3
3
|
* Utility to wait for loading to complete. Need to add a `data-test` to any
|
|
4
4
|
* loading elements. Defaults to `ll-loading` OR `loading-spinner` if test ID is not specified.
|
|
@@ -14,6 +14,21 @@ export declare function waitForLoadingToFinish(textMatch?: RegExp): Promise<void
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function cleanupNoty(): void;
|
|
16
16
|
export declare function cleanupDropdowns(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Queries and returns an array of HTML elements with the role "definition" (DD)
|
|
19
|
+
* that matches the specified text.
|
|
20
|
+
*
|
|
21
|
+
* @param textMatch - The text to match within the HTML elements. It can be a string or a regular expression.
|
|
22
|
+
* @returns An array of HTML elements that match the given text.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getAllByDescriptionTerm(textMatch: string | RegExp): HTMLElement[];
|
|
25
|
+
/**
|
|
26
|
+
* Finds the first HTML element with the role "definition" (DD) that matches the specified text.
|
|
27
|
+
*
|
|
28
|
+
* @param textMatch - The text to match within the HTML elements. It can be a string or a regular expression.
|
|
29
|
+
* @returns The matched element, or undefined if no match is found.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getByDescriptionTerm(textMatch: string | RegExp): HTMLElement | undefined;
|
|
17
32
|
/**
|
|
18
33
|
* Helper to assert and manually dismiss a notification. This is useful in scenarios where
|
|
19
34
|
* cleanupNoty() does not work as expected, such as when validating error messages in test suites
|
|
@@ -41,11 +56,13 @@ export declare function assertAndDismissNoty(text: string): Promise<void>;
|
|
|
41
56
|
* generateInvoices(10) // => Array of 10 invoice objects
|
|
42
57
|
* generateInvoices(10, { foo: 'bar' }) // => Array of 10 invoice objects, override `foo` to equal `'bar'` in each
|
|
43
58
|
*
|
|
44
|
-
* @param
|
|
45
|
-
* @returns
|
|
46
|
-
* @returns {array|object} - Array of fixture objects or single object if n = 1.
|
|
59
|
+
* @param fixtureFn - Method that generates a JSON data fixture.
|
|
60
|
+
* @returns A fixture generator that return an array of fixture objects or single object if n = 1.
|
|
47
61
|
*/
|
|
48
|
-
export declare function createFixtureGenerator(fixtureFn:
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
export declare function createFixtureGenerator<T>(fixtureFn: (overrides?: Partial<T>) => T): {
|
|
63
|
+
(): T;
|
|
64
|
+
<TNum extends 1>(num: TNum, overrides?: Partial<T>): T;
|
|
65
|
+
(num: Partial<T>): T;
|
|
66
|
+
<TNum_1 extends number>(num: TNum_1, overrides?: Partial<T>): T[];
|
|
67
|
+
};
|
|
51
68
|
export { createMockApiUtils, RestMethod };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { createMockApiUtils } from
|
|
1
|
+
import userEvent from '@testing-library/user-event';
|
|
2
|
+
import { getNodeText, screen, waitForElementToBeRemoved, } from '@testing-library/vue';
|
|
3
|
+
import { createMockApiUtils } from './api/mockEndpoints.js';
|
|
4
4
|
/**
|
|
5
5
|
* Utility to wait for loading to complete. Need to add a `data-test` to any
|
|
6
6
|
* loading elements. Defaults to `ll-loading` OR `loading-spinner` if test ID is not specified.
|
|
@@ -8,7 +8,7 @@ import { createMockApiUtils } from "./api/mockEndpoints.js";
|
|
|
8
8
|
* @param {string} testId - The data test ID to target
|
|
9
9
|
* @returns {Promise<boolean>} - Will resolve or throw if the loaders stay in the DOM.
|
|
10
10
|
*/
|
|
11
|
-
export function waitForLoadingToFinish(textMatch = /ll
|
|
11
|
+
export function waitForLoadingToFinish(textMatch = /ll-loading|loading-spinner/) {
|
|
12
12
|
return waitForElementToBeRemoved(() => [...screen.queryAllByTestId(textMatch)], { timeout: 2000 });
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
@@ -26,6 +26,56 @@ export function cleanupDropdowns() {
|
|
|
26
26
|
.querySelectorAll('.mount-point-container')
|
|
27
27
|
.forEach((elem) => elem.parentNode?.removeChild(elem));
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Type guard function to check if the provided value is an instance of HTMLElement.
|
|
31
|
+
*
|
|
32
|
+
* @param element - The value to check if it is an HTMLElement.
|
|
33
|
+
* @returns Returns true if the value is an HTMLElement, otherwise false.
|
|
34
|
+
*/
|
|
35
|
+
function isHTMLElement(element) {
|
|
36
|
+
return element instanceof HTMLElement;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks if the given HTML element contains the specified text or matches the regular expression.
|
|
40
|
+
*
|
|
41
|
+
* @param node - The HTML element to check for the presence of text.
|
|
42
|
+
* @param textMatch - The text or regular expression to match within the HTML element.
|
|
43
|
+
* @returns Returns one of the following:
|
|
44
|
+
* - true, if the element contains the exact text match;
|
|
45
|
+
* - RegExpMatchArray, if the element's text matches the regular expression;
|
|
46
|
+
* - null, if there is no match.
|
|
47
|
+
*/
|
|
48
|
+
function hasText(node, textMatch) {
|
|
49
|
+
const nodeText = getNodeText(node);
|
|
50
|
+
return nodeText === textMatch || nodeText.match(textMatch);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Queries and returns an array of HTML elements with the role "definition" (DD)
|
|
54
|
+
* that matches the specified text.
|
|
55
|
+
*
|
|
56
|
+
* @param textMatch - The text to match within the HTML elements. It can be a string or a regular expression.
|
|
57
|
+
* @returns An array of HTML elements that match the given text.
|
|
58
|
+
*/
|
|
59
|
+
export function getAllByDescriptionTerm(textMatch) {
|
|
60
|
+
return screen
|
|
61
|
+
.getAllByRole('definition')
|
|
62
|
+
.filter((term) => term.tagName === 'DD' &&
|
|
63
|
+
isHTMLElement(term.previousElementSibling) &&
|
|
64
|
+
hasText(term?.previousElementSibling, textMatch));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Finds the first HTML element with the role "definition" (DD) that matches the specified text.
|
|
68
|
+
*
|
|
69
|
+
* @param textMatch - The text to match within the HTML elements. It can be a string or a regular expression.
|
|
70
|
+
* @returns The matched element, or undefined if no match is found.
|
|
71
|
+
*/
|
|
72
|
+
export function getByDescriptionTerm(textMatch) {
|
|
73
|
+
return screen
|
|
74
|
+
.getAllByRole('definition')
|
|
75
|
+
.find((term) => term.tagName === 'DD' &&
|
|
76
|
+
isHTMLElement(term.previousElementSibling) &&
|
|
77
|
+
hasText(term?.previousElementSibling, textMatch));
|
|
78
|
+
}
|
|
29
79
|
/**
|
|
30
80
|
* Helper to assert and manually dismiss a notification. This is useful in scenarios where
|
|
31
81
|
* cleanupNoty() does not work as expected, such as when validating error messages in test suites
|
|
@@ -57,20 +107,26 @@ export async function assertAndDismissNoty(text) {
|
|
|
57
107
|
* generateInvoices(10) // => Array of 10 invoice objects
|
|
58
108
|
* generateInvoices(10, { foo: 'bar' }) // => Array of 10 invoice objects, override `foo` to equal `'bar'` in each
|
|
59
109
|
*
|
|
60
|
-
* @param
|
|
61
|
-
* @returns
|
|
62
|
-
* @returns {array|object} - Array of fixture objects or single object if n = 1.
|
|
110
|
+
* @param fixtureFn - Method that generates a JSON data fixture.
|
|
111
|
+
* @returns A fixture generator that return an array of fixture objects or single object if n = 1.
|
|
63
112
|
*/
|
|
64
113
|
export function createFixtureGenerator(fixtureFn) {
|
|
65
|
-
|
|
66
|
-
// if
|
|
67
|
-
|
|
68
|
-
if (typeof num !== 'number' || num === 1) {
|
|
114
|
+
function _generator(num = 1, overrides = {}) {
|
|
115
|
+
// if the first param is not a number, it must be the overrides
|
|
116
|
+
if (typeof num !== 'number') {
|
|
69
117
|
return fixtureFn(num);
|
|
70
118
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
119
|
+
else if (num === 1) {
|
|
120
|
+
// If num is 1, then we don't want to return an array, so just generate one with any potential overrides
|
|
121
|
+
return fixtureFn(overrides);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// Otherwise, let's generate however many requested data objects
|
|
125
|
+
// eslint-disable-next-line prefer-spread
|
|
126
|
+
return Array.apply(null, Array(num)).map(() => fixtureFn(overrides));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return _generator;
|
|
74
130
|
}
|
|
75
131
|
export { createMockApiUtils };
|
|
76
132
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,EACL,WAAW,EACX,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,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAc,CAAC"}
|
package/dist/index.spec.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@testing-library/vue';
|
|
2
|
+
import { createFixtureGenerator, getAllByDescriptionTerm, getByDescriptionTerm, } from './index';
|
|
2
3
|
describe('createFixtureGenerator()', () => {
|
|
3
4
|
it('returns a function that can generate an array of data objects', () => {
|
|
4
5
|
const generator = (overrides) => ({
|
|
@@ -25,8 +26,41 @@ describe('createFixtureGenerator()', () => {
|
|
|
25
26
|
bar: 'baz',
|
|
26
27
|
...overrides,
|
|
27
28
|
});
|
|
28
|
-
expect(createFixtureGenerator(generator)()).toEqual({
|
|
29
|
-
|
|
29
|
+
expect(createFixtureGenerator(generator)()).toEqual({
|
|
30
|
+
foo: 'bar',
|
|
31
|
+
bar: 'baz',
|
|
32
|
+
});
|
|
33
|
+
expect(createFixtureGenerator(generator)({ bar: 'yak' })).toEqual({
|
|
34
|
+
foo: 'bar',
|
|
35
|
+
bar: 'yak',
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe('getByDescriptionTerm', () => {
|
|
40
|
+
it.each `
|
|
41
|
+
term | type
|
|
42
|
+
${'foo'} | ${'string'}
|
|
43
|
+
${/foo/i} | ${'regex'}
|
|
44
|
+
${new RegExp('foo', 'i')} | ${'RegExp'}
|
|
45
|
+
`('should return the description detail for a given $type term', ({ term }) => {
|
|
46
|
+
render({ template: `<dl><dt>foo</dt><dd>bar</dd></dl>` });
|
|
47
|
+
expect(getByDescriptionTerm(term)).toHaveTextContent('bar');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('getAllByDescriptionTerm', () => {
|
|
51
|
+
it.each `
|
|
52
|
+
term | type
|
|
53
|
+
${'foo'} | ${'string'}
|
|
54
|
+
${/foo/i} | ${'regex'}
|
|
55
|
+
${new RegExp('foo', 'i')} | ${'RegExp'}
|
|
56
|
+
`('should return the description details for a given $type term', ({ term }) => {
|
|
57
|
+
render({
|
|
58
|
+
template: `<dl><dt>foo</dt><dd>bar1</dd></dl><dl><dt>foo</dt><dd>bar2</dd></dl>`,
|
|
59
|
+
});
|
|
60
|
+
const details = getAllByDescriptionTerm(term);
|
|
61
|
+
expect(details).toHaveLength(2);
|
|
62
|
+
expect(details[0]).toHaveTextContent('bar1');
|
|
63
|
+
expect(details[1]).toHaveTextContent('bar2');
|
|
30
64
|
});
|
|
31
65
|
});
|
|
32
66
|
//# sourceMappingURL=index.spec.js.map
|
package/dist/index.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.js","sourceRoot":"src/","sources":["index.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.spec.js","sourceRoot":"src/","sources":["index.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,SAAS,CAAC;AAEjB,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,EAAE,CAAC,+DAA+D,EAAE,GAAG,EAAE;QACvE,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;YAChC,GAAG,EAAE,KAAK;YACV,GAAG,EAAE,KAAK;YACV,GAAG,SAAS;SACb,CAAC,CAAC;QAEH,MAAM,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YACnD,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE;YAC1B,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE;YAC1B,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE;YAC1B,EAAE,GA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C7D,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;QACX,MAAM,CAAC,EAAE,QAAQ,EAAE,mCAAmC,EAAE,CAAC,CAAC;QAE1D,MAAM,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,EAAE,CAAC,IAAI,CAAA;;MAEH,KAAK,uBAAuB,QAAQ;MACpC,MAAM,sBAAsB,OAAO;MACnC,IAAI,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,QAAQ;GACvC,CACC,8DAA8D,EAC9D,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;QACX,MAAM,CAAC;YACL,QAAQ,EAAE,sEAAsE;SACjF,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;QAC9C,MAAM,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/dist/setup-env.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { vi } from 'vitest';
|
|
2
|
-
import { config } from '@vue/test-utils';
|
|
3
1
|
import '@testing-library/jest-dom';
|
|
2
|
+
import { config } from '@vue/test-utils';
|
|
3
|
+
import { vi } from 'vitest';
|
|
4
4
|
config.global.mocks['$t'] = (msg) => msg;
|
|
5
5
|
const oldWindowLocation = global.window.location;
|
|
6
6
|
beforeAll(() => {
|
|
7
|
-
// @ts-expect-error
|
|
7
|
+
// @ts-expect-error - dunno
|
|
8
8
|
delete global.window.location;
|
|
9
|
-
// @ts-expect-error
|
|
9
|
+
// @ts-expect-error - dunno
|
|
10
10
|
global.window.location = Object.defineProperties({}, {
|
|
11
11
|
...Object.getOwnPropertyDescriptors(oldWindowLocation),
|
|
12
12
|
assign: {
|
package/dist/setup-env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-env.js","sourceRoot":"src/","sources":["setup-env.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"setup-env.js","sourceRoot":"src/","sources":["setup-env.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC;AAEzC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;AAEjD,SAAS,CAAC,GAAG,EAAE;IACb,2BAA2B;IAC3B,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;IAE9B,2BAA2B;IAC3B,MAAM,CAAC,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAC9C,EAAE,EACF;QACE,GAAG,MAAM,CAAC,yBAAyB,CAAC,iBAAiB,CAAC;QACtD,MAAM,EAAE;YACN,YAAY,EAAE,IAAI;YAClB,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;SACf;QACD,IAAI,EAAE;YACJ,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE;gBACL,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE;aACjB;SACF;KACF,CACF,CAAC;IAEF,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;IAEtB,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE;QACjC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,GAAG,EAAE;IACZ,MAAM,CAAC,MAAM,CAAC,QAAQ,GAAG,iBAAiB,CAAC;AAC7C,CAAC,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5C,IAAI,IAAI;QACN,OAAO;IACT,CAAC;IACD,UAAU,EAAE,EAAE,CAAC,EAAE,EAAE;IACnB,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE;IAChB,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE;IACpB,SAAS,EAAE,EAAE,CAAC,EAAE,EAAE;CACnB,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,UAAU,CAAC,sBAAsB,EAAE,wBAAwB,CAAC,CAAC;AAEhE,EAAE,CAAC,UAAU,CACX,OAAO,EACP,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC,EAAE,CAAC,CACnE,CAAC;AAEF,6CAA6C;AAC7C,OAAO,CAAC,SAAS,CAAC,cAAc,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leaflink/dom-testing-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Frontend DOM testing utilities",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16",
|
|
7
7
|
"npm": ">=8"
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
|
-
".":
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./setup-env": {
|
|
16
|
+
"types": "./dist/setup-env.d.ts",
|
|
17
|
+
"import": "./dist/setup-env.js",
|
|
18
|
+
"default": "./dist/setup-env.js"
|
|
19
|
+
},
|
|
20
|
+
"./global-env": {
|
|
21
|
+
"types": "./dist/global-env.d.ts",
|
|
22
|
+
"import": "./dist/global-env.js",
|
|
23
|
+
"default": "./dist/global-env.js"
|
|
24
|
+
}
|
|
11
25
|
},
|
|
12
26
|
"type": "module",
|
|
13
27
|
"types": "./dist/index.d.ts",
|
|
@@ -19,32 +33,12 @@
|
|
|
19
33
|
],
|
|
20
34
|
"scripts": {
|
|
21
35
|
"build": "tsc",
|
|
36
|
+
"fix": "npm run lint -- --fix",
|
|
37
|
+
"lint": "eslint .",
|
|
22
38
|
"lint:commits": "commitlint",
|
|
23
39
|
"test": "vitest --reporter verbose"
|
|
24
40
|
},
|
|
25
41
|
"license": "MIT",
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"@commitlint/cli": "^17.4.4",
|
|
28
|
-
"@commitlint/config-conventional": "^17.4.4",
|
|
29
|
-
"@vitest/coverage-c8": "^0.29.2",
|
|
30
|
-
"jsdom": "^21.1.1",
|
|
31
|
-
"typescript": "^4.9.5",
|
|
32
|
-
"vite": "^4.1.4",
|
|
33
|
-
"vitest": "^0.29.3"
|
|
34
|
-
},
|
|
35
|
-
"commitlint": {
|
|
36
|
-
"extends": [
|
|
37
|
-
"@commitlint/config-conventional"
|
|
38
|
-
],
|
|
39
|
-
"rules": {
|
|
40
|
-
"scope-case": [
|
|
41
|
-
0
|
|
42
|
-
],
|
|
43
|
-
"body-max-line-length": [
|
|
44
|
-
0
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
42
|
"dependencies": {
|
|
49
43
|
"@testing-library/cypress": "^9.0.0",
|
|
50
44
|
"@testing-library/jest-dom": "^5.16.5",
|
|
@@ -53,5 +47,23 @@
|
|
|
53
47
|
"@types/segment-analytics": "^0.0.34",
|
|
54
48
|
"eslint-plugin-testing-library": "^5.10.2",
|
|
55
49
|
"msw": "^0.27.2"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@vitest/coverage-c8": "^0.29.2",
|
|
53
|
+
"eslint": "^8.49.0",
|
|
54
|
+
"eslint-config-leaflink": "^1.17.0",
|
|
55
|
+
"jsdom": "^21.1.1",
|
|
56
|
+
"postcss-html": "^1.5.0",
|
|
57
|
+
"stylelint": "^15.10.3",
|
|
58
|
+
"stylelint-config-standard-scss": "^10.0.0",
|
|
59
|
+
"stylelint-config-standard-vue": "^1.0.0",
|
|
60
|
+
"typescript": "^4.9.5",
|
|
61
|
+
"vite": "^4.1.4",
|
|
62
|
+
"vitest": "^0.29.3"
|
|
63
|
+
},
|
|
64
|
+
"eslintConfig": {
|
|
65
|
+
"extends": [
|
|
66
|
+
"leaflink"
|
|
67
|
+
]
|
|
56
68
|
}
|
|
57
69
|
}
|