Skip to content

Commit

Permalink
test: refactor tests of warnUndefinedElement
Browse files Browse the repository at this point in the history
Signed-off-by: Rong Sen Ng (motss) <[email protected]>
  • Loading branch information
motss committed Jan 6, 2024
1 parent 755e9c7 commit 264612e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/__tests__/helpers/warn-undefined-element.test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import { expect } from '@open-wc/testing';
import { stubMethod } from 'hanbi';
import { describe, expect, it, vi } from 'vitest';

import { warnUndefinedElement } from '../../helpers/warn-undefined-element';
import { RootElement } from '../../root-element/root-element';

const warn = stubMethod(console, 'warn');
const warn = vi.spyOn(window.console, 'warn');

describe(warnUndefinedElement.name, () => {
const elementName = 'test-element' as const;
const elementName2 = 'test-element-2' as const;

afterEach(() => {
warn.reset();
});

it('does not warn defined element', () => {
globalThis.customElements.define(elementName, class A extends RootElement {});

warnUndefinedElement(elementName);

expect(warn.called).false;
expect(warn).not.toBeCalled();
});

it('warns undefined element', () => {
warnUndefinedElement(elementName2);

expect(warn.lastCall?.args).deep.equal([`${elementName2} is required`]);
expect(warn).toBeCalledWith(`${elementName2} is required`);
});
});
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default defineConfig({
'**/*test*/helpers/to-next-selected-date.test.ts',
'**/*test*/helpers/to-resolved-date.test.ts',
'**/*test*/helpers/to-year-list.test.ts',
'**/*test*/helpers/warn-undefined-element.test.ts',
// '**/*test*/date-picker-input/**.test.ts',
],
clearMocks: true,
Expand Down

0 comments on commit 264612e

Please sign in to comment.