Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active October 7, 2018 07:39
Show Gist options
  • Save YonatanKra/de42be2fa5499157169ef141ba377998 to your computer and use it in GitHub Desktop.
Save YonatanKra/de42be2fa5499157169ef141ba377998 to your computer and use it in GitHub Desktop.
import {MyCustomElementService} from './my-custom-element.service.ts';
class MyCustomElementMock extends HTMLElement{
config: ConfigModel;
constructor() {
super();
}
}
window.customElements.define('my-element', MyCustomElementMock);
// now I am testing the service itself
describe('custom element service', () => {
it('should do something', () => {
const service = new MyCustomElementService();
const config = new ConfigModel();
const element = service.doSomething(config);
expect(element.config).toEqual(config);
});
});
import {MyCustomElement} from '../customElements/myCustomElement/my-custom-element.ts';
export class MyCustomElementService {
doSomething(config) {
const myElement = <MyCustomElement>document.createElement('my-element'); //If I inferer the original custom element here, tests won't work as well
myElement.config = config;
return myElement;
}
}
@Avinkav
Copy link

Avinkav commented Oct 7, 2018

export class MyCustomElementService {
  doSomething(config): MyCustomElementMock {
    const myElement = document.createElement('my-element') as MyCustomElementMock;
    myElement.config = config;
    return myElement;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment