Skip to content

Commit

Permalink
fix: don't console.warn on tags
Browse files Browse the repository at this point in the history
you should instead be given the opportunity to override a tag if you'd
like.
  • Loading branch information
sebkolind committed May 20, 2024
1 parent 6499ab4 commit 5878c1a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.31] - 2024-05-20

### Fixed

- Don't `console.warn` on existing tags. You should have full control over your tags.

## [0.0.29] & [0.0.30] - 2024-05-16

- A mistake was made in the versioning, so these are re-releases of `0.0.28`. The changelog is kept for transparency.
Expand Down
27 changes: 0 additions & 27 deletions src/__tests__/tags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,4 @@ describe('tags.ts', () => {
expect(el.$tent.attributes['data-bar']).toBe('baz');
expect(el.$tent.attributes['onClick']).toBe(fn);
});

test('warns when using a predefined tag when not in production', () => {
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});

createTag(['div', 'test', {}]);

expect(spy).toHaveBeenCalledWith(
'Tag "div" is a predefined tag, use tags.div instead',
);

spy.mockRestore();
});

test('does not warn when using a predefined tag when in production', () => {
const OLD_ENV = process.env.NODE_ENV;
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});

process.env.NODE_ENV = 'production';

createTag(['div', 'test', {}]);

expect(spy).not.toHaveBeenCalled();

spy.mockRestore();

process.env.NODE_ENV = OLD_ENV;
});
});
4 changes: 0 additions & 4 deletions src/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { type Tags, type Context, type TentNode } from './types';
function createTag(context: Context) {
const [tag, children, attributes] = context;

if (tags[tag] && process.env.NODE_ENV !== 'production') {
console.warn(`Tag "${tag}" is a predefined tag, use tags.${tag} instead`);
}

const el = document.createElement(tag) as TentNode;

el.$tent = {
Expand Down

0 comments on commit 5878c1a

Please sign in to comment.