Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support testing widgets with nested typed children #898

Merged
merged 4 commits into from
Apr 29, 2021

Conversation

agubler
Copy link
Member

@agubler agubler commented Apr 22, 2021

Type: feature

The following has been addressed in the PR:

Description:

Provides an API to support testing widgets with complex, nested typed children, for example:

interface TypedChildren {
    headers: {
        headerA: (value: string, num: number) => RenderResult    
    },
    cells: {
        columnA: (value: string) => RenderResult
    },
    footer: RenderResult
}

Currently the test renderer's child API enables consumers to instruct the renderer to resolve children to one level, renderer.child(WrappedWidget, 'child', 'params', 'for', 'renderer'); this change adds an additional overload that enables users to provide params to resolve multiple children, including nested children. The function is typed to require all functional children to have params returned and the params are typed for the functional child. Using the example child interface above, this would look like:

renderer.child(WrappedWidget, (params) => {
    return {
        headers: {
            headerA: params(['text', 12345])
        },
        cells: {
            columnA: params(['text'])
        }
    };
}); 

Note: The params function was required for typings, otherwise the parameters for the functions were typed as tuples not arrays so need explicit casting i.e. ['text'] as [string] - using an injected function seemed to be a more user friendly approach.

Includes fixes required for parsing nested children in assertRender

Resolves #897

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7d8a7a1:

Sandbox Source
dojo/dojo-codesandbox-template Configuration

@codecov
Copy link

codecov bot commented Apr 22, 2021

Codecov Report

Merging #898 (7d8a7a1) into master (36aae1a) will increase coverage by 0.04%.
The diff coverage is 98.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #898      +/-   ##
==========================================
+ Coverage   94.54%   94.59%   +0.04%     
==========================================
  Files         127      127              
  Lines        8121     8135      +14     
  Branches     1896     1899       +3     
==========================================
+ Hits         7678     7695      +17     
+ Misses        443      440       -3     
Impacted Files Coverage Δ
src/testing/assertRender.ts 98.18% <96.66%> (+2.31%) ⬆️
src/testing/decorate.ts 98.36% <100.00%> (+0.34%) ⬆️
src/testing/renderer.ts 97.36% <100.00%> (+0.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 36aae1a...7d8a7a1. Read the comment docs.

@agubler agubler merged commit ccaedb3 into dojo:master Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to test deeply nested children when using typed children
2 participants