Skip to content

Commit

Permalink
test: add tests for warnUndefinedElement with hanbi for stubbing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
motss committed Nov 28, 2021
1 parent e493bfb commit 1f92479
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"eslint-plugin-promise": "^5.1.1",
"eslint-plugin-regexp": "^1.5.1",
"eslint-plugin-simple-import-sort": "^7.0.0",
"hanbi": "^1.0.1",
"nano-staged": "^0.3.1",
"typescript": "^4.5.2"
},
Expand Down
30 changes: 30 additions & 0 deletions src/__tests__/helpers/warn-undefined-element.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect } from '@open-wc/testing';
import { stubMethod } from 'hanbi';

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

const warn = stubMethod(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;
});

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

expect(warn.lastCall?.args).deep.equal([`${elementName2} is required`]);
});
});

0 comments on commit 1f92479

Please sign in to comment.