ionic-team / stencil-component-starter

Minimal starter project for building shareable web components with Stencil
https://github.com/ionic-team/stencil
MIT License
278 stars 129 forks source link

Stencil starter app unit tests are broken #65

Closed liron-navon closed 5 years ago

liron-navon commented 5 years ago

Made a PR for this: https://github.com/ionic-team/stencil-component-starter/pull/66

Stencil version:

 @stencil/core@0.15.2

I'm submitting a:

[ X] bug report [ ] feature request [ ] support request

Current behavior: Default tests fails with the starter app.

Expected behavior: Default tests should pass.

Steps to reproduce: In the terminal run:

npm init stencil # => component
npm test

Related code: The default code for the default component spec:

import { MyComponent } from './my-component';

describe('my-component', () => {
  it('builds', () => {
    expect(new MyComponent()).toBeTruthy();
  });

  describe('formatting', () => {
    it('returns empty string for no names defined', () => {
      const component = new MyComponent();

      // format does not exist on the component...

      expect(component.format()).toEqual('');
    });
  });
});

Other information:

I guess the "format" function was changed to "getText", but was not changed in the tests?

The error logs:

 PASS  src/components/my-component/my-component.e2e.ts
 FAIL  src/components/my-component/my-component.spec.ts
  ● my-component › formatting › returns empty string for no names defined

    TypeError: component.format is not a function

       9 |     it('returns empty string for no names defined', () => {
      10 |       const component = new MyComponent();
    > 11 |       expect(component.format()).toEqual('');
         |                        ^
      12 |     });
      13 | 
      14 |     it('formats just first names', () => {
liron-navon commented 5 years ago

Made a PR for this: https://github.com/ionic-team/stencil-component-starter/pull/66

kensodemann commented 5 years ago

Thank you for the PR. Part of the refactoring that led to this was designed to make the stater model an overall better pattern where "business logic" is moved out of the components and into plain old Typescript classes, keeping the components light-weight. Think "pipes" and "services" from the Angular world. This one would be more like a "pipe".

The format() tests should have been moved to a util.spec.ts file at the time format() was moved to the util.ts file. Commented as such on the PR.

kensodemann commented 5 years ago

Moved the existing unit tests to util.spec.ts via this commit: https://github.com/ionic-team/stencil-component-starter/commit/e65f5071df4658b725eddffb540b9ab7bf652803