add test for umb-context-provider

This commit is contained in:
Jacob Overgaard
2022-08-09 15:57:44 +02:00
parent 91e3a76afb
commit fc7f539db5
2 changed files with 41 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
import { expect, fixture, html } from '@open-wc/testing';
import { LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
import { UmbContextConsumerMixin } from './context-consumer.mixin';
import { UmbContextProviderElement } from './context-provider.element';
@customElement('umb-context-test')
export class ContextTestElement extends UmbContextConsumerMixin(LitElement) {
public value: string | null = null;
constructor() {
super();
this.consumeContext('test-context', (value) => {
this.value = value;
});
}
}
describe('UmbContextProvider', () => {
let element: UmbContextProviderElement;
let consumer: ContextTestElement;
const contextValue = 'test-value';
beforeEach(async () => {
element = await fixture(
html` <umb-context-provider key="test-context" .value=${contextValue}>
<umb-context-test></umb-context-test>
</umb-context-provider>`
);
consumer = element.getElementsByTagName('umb-context-test')[0] as ContextTestElement;
});
it('is defined with its own instance', () => {
expect(element).to.be.instanceOf(UmbContextProviderElement);
});
it('provides the context', () => {
expect(consumer.value).to.equal(contextValue);
});
});

View File

@@ -10,7 +10,7 @@ export class UmbContextProviderElement extends UmbContextProviderMixin(LitElemen
* @required
*/
@property({ type: Object })
value!: unknown;
value: unknown;
/**
* The key to provide to the context.