How to use the @open-wc/testing-helpers.defineCE function in @open-wc/testing-helpers

To help you get started, we’ve selected a few @open-wc/testing-helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github corpusculejs / corpuscule / packages / element / __tests__ / query.ts View on Github external
this.attachShadow({mode: 'open'});
        }

        public connectedCallback(): void {
          // tslint:disable-next-line:no-inner-html
          this.shadowRoot!.innerHTML = `
            <div></div>
            <div class="wrapper">
              <div>Test text</div>
            </div>
          `;
        }
      }

      const tag = defineCE(Test);
      const test = await fixture(`&lt;${tag}&gt;`);

      expect(test.target).toEqual(jasmine.any(HTMLElement));
      expect(test.target.textContent).toBe('Test text');
    });
github corpusculejs / corpuscule / packages / context / __tests__ / index.ts View on Github external
it('throws an error if no provider exists for context', done =&gt; {
    @consumer
    class Consumer extends CustomElement {
      @value public contextValue!: number;
    }

    const tag = defineCE(Consumer);

    window.onerror = message =&gt; {
      expect(message).toContain('No provider found for Consumer');
      done();
    };

    fixture(`&lt;${tag}&gt;`);
  });
github corpusculejs / corpuscule / packages / element / __tests__ / attribute.ts View on Github external
it('initializes and fills "observedAttributes"', () =&gt; {
      class Test extends CustomElement {
        public static readonly observedAttributes: ReadonlyArray = [];

        @attribute('a1', Boolean)
        public attr1: boolean | null = null;

        @attribute('a2', String)
        public attr2: string | null = null;
      }

      defineCE(Test);
      expect(Test.observedAttributes).toEqual(['a1', 'a2']);
    });
github corpusculejs / corpuscule / packages / form / __tests__ / field.ts View on Github external
@gear() public readonly state!: FormState;

          @option()
          public onSubmit(): void {}
        }

        @field()
        class Field extends CustomElement {
          @gear() public readonly formApi!: FormApi;
          @gear() public readonly input!: FieldInputProps;
          @gear() public readonly meta!: FieldMetaProps;

          @option() public readonly name: string = 'test';
        }

        const fieldTag = defineCE(Field);
        const formTag = defineCE(Form);

        const formElement = await fixture(`
          &lt;${formTag}&gt;
            &lt;${fieldTag}&gt;
              <input type="text">
            
          
        `);

        const inputElement = formElement.querySelector('input')!;

        inputElement.dispatchEvent(new Event('focusin', {bubbles: true}));

        expect(state.focus).toHaveBeenCalled();
      });
github corpusculejs / corpuscule / packages / context / __tests__ / index.ts View on Github external
it('provides context for all consumers', async () =&gt; {
    @provider
    class Provider extends CustomElement {
      @value public providingValue: number = 2;
    }

    @consumer
    class Consumer extends CustomElement {
      @value public contextValue!: number;
    }

    const providerTag = defineCE(Provider);
    const consumerTag = defineCE(Consumer);

    const providerElement = await fixture(`
        &lt;${providerTag}&gt;
          &lt;${consumerTag}&gt;
          &lt;${consumerTag}&gt;
        
      `);

    const [consumerElement1, consumerElement2] = Array.from(
      providerElement.children as any,
    );

    expect(consumerElement1.contextValue).toBe(2);
    expect(consumerElement2.contextValue).toBe(2);
  });
github corpusculejs / corpuscule / packages / form / __tests__ / form.ts View on Github external
@form()
      class Test extends CustomElement {
        @gear() public readonly formApi!: FormApi;
        @gear() public readonly state!: FormState;

        @option()
        public initialValues: object = {
          bar: 2,
          foo: 1,
        };

        @option()
        public onSubmit(): void {}
      }

      const tag = unsafeStatic(defineCE(Test));
      await fixture(
        html`&lt;${tag} .initialValues="${{
          bar: 2,
          foo: 1,
        }}"&gt;`,
      );

      expect(formSpyObject.initialize).not.toHaveBeenCalled();
    });
github corpusculejs / corpuscule / packages / form / __tests__ / field.ts View on Github external
@option()
          public onSubmit(): void {}
        }

        @field()
        class Field extends CustomElement {
          @gear() public readonly formApi!: FormApi;
          @gear() public readonly input!: FieldInputProps;
          @gear() public readonly meta!: FieldMetaProps;

          @option() public readonly name: string = 'test';
        }

        const fieldTag = defineCE(Field);
        const formTag = defineCE(Form);

        const formElement = await fixture(`
          &lt;${formTag}&gt;
            &lt;${fieldTag}&gt;
              <input type="text">
            
          
        `);

        const inputElement = formElement.querySelector('input')!;

        inputElement.dispatchEvent(new Event('focusin', {bubbles: true}));

        expect(state.focus).toHaveBeenCalled();
      });
github corpusculejs / corpuscule / packages / element / __tests__ / attribute.ts View on Github external
it('sets string attribute', async () =&gt; {
      class Test extends CustomElement {
        public static readonly observedAttributes: ReadonlyArray = [];

        @attribute('attr', String)
        public attribute: string | null = null;
      }

      const tag = defineCE(Test);
      const test = await fixture(`&lt;${tag}&gt;`);

      test.attribute = 'str';

      expect(test.getAttribute('attr')).toBe('str');
    });
github corpusculejs / corpuscule / test / utils.js View on Github external
export const createSimpleContext = async (Provider, Consumer) =&gt; {
  const providerTag = defineCE(Provider);
  const consumerTag = defineCE(Consumer);

  const providerElement = await fixture(`
    &lt;${providerTag}&gt;
      &lt;${consumerTag}&gt;
    
  `);

  return [providerElement, providerElement.children[0]];
};
github corpusculejs / corpuscule / test / utils.js View on Github external
export const createSimpleContext = async (Provider, Consumer) =&gt; {
  const providerTag = defineCE(Provider);
  const consumerTag = defineCE(Consumer);

  const providerElement = await fixture(`
    &lt;${providerTag}&gt;
      &lt;${consumerTag}&gt;
    
  `);

  return [providerElement, providerElement.children[0]];
};