-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(Storybook): updates new test docs to v7 changes
- Loading branch information
Showing
14 changed files
with
19,789 additions
and
204 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/@lightningjs/ui-components-test-utils/src/docs/Overview.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{/* prettier-ignore */} | ||
{/*Copyright 2023 Comcast Cable Communications Management, LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
SPDX-License-Identifier: Apache-2.0\*/} | ||
|
||
import { Meta } from '@storybook/blocks'; | ||
|
||
<Meta title="Documentation / Unit Testing / Overview" /> | ||
|
||
# @lightningjs/ui-components-test-utils | ||
|
||
The `@lightningjs/ui-components-test-utils` package provides 2 artifacts to assist with unit testing Lightning components. | ||
|
||
1. **Test Renderer** | ||
|
||
- [create](/story/docs-unit-testing-test-renderer-create--page): Generates a `testRenderer` object with built in utilities for unit testing Lightning Components. | ||
- [toJSON](/story/docs-unit-testing-test-renderer-tojson--page): Converts Lightning components to JSON to be used in [Jest Snapshot Tests](https://jestjs.io/docs/snapshot-testing) | ||
|
||
2. **Test Utils** | ||
|
||
- [makeCreateComponent](/story/docs-unit-testing-test-utils-makecreatecomponent--page): Returns a `createComponent` function which is used to generate an instance of a component to run unit test cases against. | ||
- [completeAnimation](/story/docs-unit-testing-test-utils-completeanimation--page): Returns a Promise that resolves once all animating properties have updated to their target value(s). | ||
- [fastForward](/story/docs-unit-testing-test-utils-fastforward--page): Force all running Lightning Transitions on one or more Lightning Elements to finish and update the transitioning property to its target value immediately. | ||
- [nextTick](/story/docs-unit-testing-test-utils-nexttick--page): Creates a Promise that resolves after a defined amount of time. If no amount of time is specified, the Promise will resolve immediately. |
33 changes: 0 additions & 33 deletions
33
packages/@lightningjs/ui-components-test-utils/src/docs/Overview.stories.mdx
This file was deleted.
Oops, something went wrong.
31 changes: 14 additions & 17 deletions
31
.../src/docs/TestRenderer/create.stories.mdx → ...st-utils/src/docs/TestRenderer/create.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/@lightningjs/ui-components-test-utils/src/docs/TestRenderer/toJSON.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{/* prettier-ignore */} | ||
{/*Copyright 2023 Comcast Cable Communications Management, LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
SPDX-License-Identifier: Apache-2.0\*/} | ||
|
||
import { Meta } from '@storybook/blocks'; | ||
|
||
<Meta title="Documentation / Unit Testing / Test Renderer / toJSON" /> | ||
|
||
# toJSON | ||
|
||
Convert Lightning components to JSON to be used in [Jest Snapshot Tests](https://jestjs.io/docs/snapshot-testing). | ||
|
||
## Arguments | ||
|
||
`toJSON(element, { children } = {})` | ||
|
||
| argument | type | default | description | | ||
| -------------- | ----------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------ | | ||
| element | Lightning.Element | - | element to create JSON from | | ||
| \{ children \} | object | \{ children: 100 \} | object with `children` property to define the number of layers deep in the render tree should be converted to JSON | | ||
|
||
<br /> | ||
|
||
##### Example: Snapshot testing using `TestRenderer.toJSON` and Jest's `toMatchSnapshot` matcher | ||
|
||
```js | ||
import lng from '@lightningjs/core'; | ||
import { TestRenderer } from '@lightningjs/ui-components-test-utils'; | ||
|
||
class TestComp extends lng.Component { | ||
static _template() { | ||
return { | ||
TextElement: { | ||
text: { text: 'foo' } | ||
} | ||
}; | ||
} | ||
} | ||
|
||
it('should match the snapshot for the component', () => { | ||
const testRenderer = TestRenderer.create({ Component: { type: TestComp } }); | ||
const testCompInstance = testRenderer.getInstance(); | ||
const tree = TestRenderer.toJSON(testCompInstance, { children: 1 }); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
``` |
60 changes: 0 additions & 60 deletions
60
.../@lightningjs/ui-components-test-utils/src/docs/TestRenderer/toJSON.stories.mdx
This file was deleted.
Oops, something went wrong.
31 changes: 14 additions & 17 deletions
31
...s/TestUtils/completeAnimation.stories.mdx → .../src/docs/TestUtils/completeAnimation.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 14 additions & 17 deletions
31
...TestUtils/makeCreateComponent.stories.mdx → ...rc/docs/TestUtils/makeCreateComponent.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/@lightningjs/ui-components-test-utils/src/docs/TestUtils/nextTick.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{/* prettier-ignore */} | ||
{/*Copyright 2023 Comcast Cable Communications Management, LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
SPDX-License-Identifier: Apache-2.0\*/} | ||
|
||
import { Meta } from '@storybook/blocks'; | ||
|
||
<Meta title="Documentation / Unit Testing / Test Utils / nextTick" /> | ||
|
||
# nextTick | ||
|
||
Creates a Promise that resolves after a defined amount of time. If no amount of time is specified, the Promise will resolve immediately. | ||
|
||
## Arguments | ||
|
||
`nextTick(wait = 0)` | ||
|
||
| argument | type | default | description | | ||
| -------- | ------ | ------- | --------------------------------------------------------------------- | | ||
| wait | number | 0 | amount of time (in milliseconds) before the returned Promise resolves | |
Oops, something went wrong.