Skip to content

Commit

Permalink
test: add main tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebkolind committed May 27, 2024
1 parent 0ac949b commit d9919af
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Component, mount, tags } from '../main';

describe('main', () => {
test('`null` element', () => {
const el = document.querySelector('.not-defined');

expect(mount(el, {} as Component)).toBe(undefined);
});

test('setting an unknown state property', () => {
const el = document.createElement('div');

expect(() =>
mount(el, {
state: { count: 0 },
view: ({ state }) =>
tags.div('', { mounted: () => state['unknown']++ }),
}),
).toThrow();
});

test('setting a state property to the same value', () => {
const el = document.createElement('div');

expect(() =>
mount(el, {
state: { count: 0 },
view: ({ state }) => tags.div('', { mounted: () => (state.count = 0) }),
}),
).not.toThrow();
});
});

0 comments on commit d9919af

Please sign in to comment.