-
Notifications
You must be signed in to change notification settings - Fork 91
feat: use render without render options #21
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
Conversation
Hi @flakolefluk, thanks for the PR! Could you also add a test, you can take a look at https://github.com/testing-library/angular-testing-library/blob/master/projects/testing-library/tests/counter/counter.spec.ts#L68 for example. To run the tests you can run |
Thanks! Test added. |
@@ -15,7 +15,9 @@ class WrapperComponent implements OnInit { | |||
|
|||
export async function render<T>( | |||
templateOrComponent: string | Type<T>, | |||
{ | |||
renderOptions: RenderOptions<T> = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't clear in the issue description, but this should only be possible when we define our components as a type, for example of you would use render('<component></component>')
we should still make it required to define render options. This is because we have to have to component's type to add it to the declarations in the Angular DI.
That's why I would propose the following types if you agree:
export async function render<T>(templateOrComponent: string, renderOptions: RenderOptions<T>);
export async function render<T>(templateOrComponent: Type<T>, renderOptions?: RenderOptions<T>);
export async function render<T>(
templateOrComponent: string | Type<T>,
renderOptions: RenderOptions<T> = {},
): Promise<RenderResult>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Tim.
I was aware of this issue, but I didn't want to change what was already there. At the moment it's possible to create a component with a string template and an empty object. That will fail because of an unknown element. Making it not optional with string templates will still allow to pass an empty object. I agree this would give a better hint.
also: Bug or feature, these tests will pass (haven't done more research yet)
test(`should render title in a h1 tag`, async () => {
const { container } = await render('<app-root></app-root>', {
declarations: [AppComponent],
});
expect(container.querySelector('h1').textContent).toContain('Welcome to app!');
});
// string template and no options
test(`should render title in a h1 tag`, async () => {
const { container } = await render('<app-root></app-root>');
expect(container.querySelector('h1').textContent).toContain('Welcome to app!');
});
removing the first test, will make the second one fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right about the string template with an empty object. To solve this we could create a new RenderOptions
interface.
For the failing test, it's an issue. And probably because of the configureJest()
method that does not clear up correctly after a test. This isn't "published" yet and was more a POC for now 🙂
Thanks @flakolefluk , would it be OK to add you to our contributors list? |
🎉 This PR is included in version 6.1.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Sure! Thanks! |
@allcontributors please add @flakolefluk for code,tests |
I couldn't determine any contributions to add, did you specify any contributions? |
@allcontributors please add @flakolefluk for code, test |
I've put up a pull request to add @flakolefluk! 🎉 |
Moved object destructuring with default values to the function implementation.
Sorry, did not see any guidelines for contribution :/
closes #17