Skip to content

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

Merged
merged 3 commits into from
Jun 11, 2019

Conversation

flakolefluk
Copy link
Contributor

@flakolefluk flakolefluk commented May 31, 2019

Moved object destructuring with default values to the function implementation.

Sorry, did not see any guidelines for contribution :/

closes #17

@timdeschryver
Copy link
Member

Hi @flakolefluk, thanks for the PR!
I will create the contribution guidelines soon, you're the one of first contributors 🙂

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 npm run test.
To test the application you can run npm run build to build the library and next you can run npm run test:app to test the app.

@flakolefluk
Copy link
Contributor Author

Thanks! Test added.

@@ -15,7 +15,9 @@ class WrapperComponent implements OnInit {

export async function render<T>(
templateOrComponent: string | Type<T>,
{
renderOptions: RenderOptions<T> = {},
Copy link
Member

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>

Copy link
Contributor Author

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.

Copy link
Member

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 🙂

@timdeschryver
Copy link
Member

Thanks @flakolefluk , would it be OK to add you to our contributors list?
https://github.com/testing-library/angular-testing-library#contributors

@timdeschryver timdeschryver merged commit a9f0065 into testing-library:master Jun 11, 2019
@timdeschryver
Copy link
Member

🎉 This PR is included in version 6.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@flakolefluk
Copy link
Contributor Author

Thanks @flakolefluk , would it be OK to add you to our contributors list?
https://github.com/testing-library/angular-testing-library#contributors

Sure! Thanks!

@timdeschryver
Copy link
Member

@allcontributors please add @flakolefluk for code,tests

@allcontributors
Copy link
Contributor

@timdeschryver

I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use valid contribution names.

@timdeschryver
Copy link
Member

@allcontributors please add @flakolefluk for code, test

@allcontributors
Copy link
Contributor

@timdeschryver

I've put up a pull request to add @flakolefluk! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: using render without RenderOptions
2 participants