GithubHelp home page GithubHelp logo

Comments (5)

marksy avatar marksy commented on May 27, 2024 1

Ah yes, you're right! Thanks, I missed that part in the docs.

from stencil.

christian-bromann avatar christian-bromann commented on May 27, 2024 1

@marksy thanks for clarifying! I caught the problem: when you run unit tests, make sure to include all components that are used in your component in the components list. As ComposedComponent uses TestComponent you have to import and add TestComponent here too. Here is the patch that will make the test pass:

diff --git a/src/components/composed-component/test/composed-component.spec.tsx b/src/components/composed-component/test/composed-component.spec.tsx
index 0bb30f1..3cd9d09 100644
--- a/src/components/composed-component/test/composed-component.spec.tsx
+++ b/src/components/composed-component/test/composed-component.spec.tsx
@@ -1,17 +1,27 @@
 import { newSpecPage } from '@stencil/core/testing';
-import { ComposedComponent} from '../composed-component';
+import { ComposedComponent } from '../composed-component';
+import { TestComponent } from '../../test-component/test-component';
 
 describe('composed-component', () => {
     it('renders', async () => {
         const page = await newSpecPage({
-            components: [ComposedComponent],
+            components: [ComposedComponent, TestComponent],
             html: `<composed-component></composed-component>`,
         });
         expect(page.root).toEqualHtml(`
       <composed-component>
         <mock:shadow-root>
           <p>Composed Component</p>
-          <test-component data-testid="example"></test-component>
+          <test-component>
+            <mock:shadow-root>
+              <p>
+                Test Component
+              </p>
+              <div data-testid="example">
+                hi there!
+              </div>
+            </mock:shadow-root>
+          </test-component>
         </mock:shadow-root>
       </composed-component>
     `);

Note: you can totally exclude the component from our unit test if you don't care about how it is being rendered. In this case though Stencil doesn't know about it and just represents it in the same way you defined it in the render function which is <test-component dataTestid="example"></test-component>.

Let me know if this clears things up!

from stencil.

christian-bromann avatar christian-bromann commented on May 27, 2024

Hey @marksy 👋 thanks for raising the issue!

I looked into your reproducible example and wasn't quite able to reproduce the problem. If TestComponent defines a prop with the name dataTestid, then it should be used as following:

  • <test-component dataTestid="example"></test-component> in a JSX file and
  • <test-component data-testid="example"></test-component> in a html file.

After fixing it, and adding a www output target I get a correctly rendered component:

Screenshot 2024-02-21 at 3 45 54 PM

The changes I made for this were as follows:

diff --git a/.gitignore b/.gitignore
index fa25637..2854b38 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,3 +40,5 @@ src/**/*.generated.*
 !.yarn/releases
 !.yarn/sdks
 !.yarn/versions
+
+www
\ No newline at end of file
diff --git a/src/components/composed-component/composed-component.tsx b/src/components/composed-component/composed-component.tsx
index b176127..38f483b 100644
--- a/src/components/composed-component/composed-component.tsx
+++ b/src/components/composed-component/composed-component.tsx
@@ -10,7 +10,7 @@ export class ComposedComponent {
         return (
             <Host>
                 <p>Composed Component</p>
-                <test-component data-testid="example"></test-component>
+                <test-component dataTestid="example"></test-component>
             </Host>
         );
     }
diff --git a/src/index.html b/src/index.html
index c81244d..fe97c8e 100644
--- a/src/index.html
+++ b/src/index.html
@@ -39,8 +39,11 @@
             onErrorChange();
         }, false);
     </script>
+    <script type="module" src="/build/tui.esm.js"></script>
+
 </head>
 <body>
+    <composed-component></composed-component>
 <!-- This file is intentionally empty. Components are rendered by stories, this index.html is only used to host the Stencil dev server error modal. -->
 </body>
 </html>
diff --git a/stencil.config.ts b/stencil.config.ts
index 0ed5add..83d1a5e 100644
--- a/stencil.config.ts
+++ b/stencil.config.ts
@@ -44,6 +44,9 @@ export const config: Config = {
             type: 'docs-json',
             file: `${distDirs.stencil}/components.json`,
         },
+        {
+            type: 'www',
+        },
         reactOutputTarget({
             componentCorePackage: '../types',
             proxiesFile: `${distDirs.stencil}/react/index.ts`,

I expect the required camelCased prop (e.g., dataTestid) to be used as a kebab-cased prop

The Stencil documentation says it as such:
Screenshot 2024-02-21 at 3 55 48 PM

kebab-cases only in html files and camelCased in JSX files.

from stencil.

marksy avatar marksy commented on May 27, 2024

Sorry for re-opening this issue.

I got confused - as I was trying thing to fix the original issue of the test not working correctly, which resulted in my trying to fix it and seeing the typescript issue.

The actual issue I'm encountering is when I run the test, it fails by not parsing the kebab-cased prop.

image

I've updated my example repo.

Unless I should be camelCasing in the test too (i doubt it because it's html syntax)?

from stencil.

marksy avatar marksy commented on May 27, 2024

Ah awesome thanks that makes sense now.

from stencil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.