Skip to content

Commit

Permalink
test: add type testing (atomiks#743)
Browse files Browse the repository at this point in the history
* test: add type testing

* chore: fix CI

* chore: run types tests before any other
  • Loading branch information
KubaJastrz authored Mar 25, 2020
1 parent 7c80e61 commit 11c1836
Show file tree
Hide file tree
Showing 6 changed files with 724 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- stage: Code check
name: Type checking
script: npm run check-types
script: npm run test:types

- stage: Tests
name: DOM tests
Expand Down
58 changes: 58 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {expectType} from 'tsd';
import tippy, {
Instance,
delegate,
DelegateInstance,
createSingleton,
Plugin,
animateFill,
followCursor,
inlinePositioning,
sticky,
hideAll,
roundArrow,
} from '.';

const singleTarget = document.createElement('div');
const mulitpleTargets = document.querySelectorAll('div');

expectType<Instance>(tippy(singleTarget));
expectType<Instance>(tippy(singleTarget, {content: 'hello'}));

expectType<Instance[]>(tippy(mulitpleTargets));
expectType<Instance[]>(tippy(mulitpleTargets, {content: 'hello'}));

expectType<DelegateInstance>(delegate(singleTarget, {target: '.child'}));
expectType<DelegateInstance>(
delegate(singleTarget, {target: '.child', content: 'hello'})
);

expectType<DelegateInstance[]>(delegate(mulitpleTargets, {target: '.child'}));
expectType<DelegateInstance[]>(
delegate(mulitpleTargets, {target: '.child', content: 'hello'})
);

const tippyInstances = [tippy(singleTarget), tippy(singleTarget)];
expectType<Instance>(createSingleton(tippyInstances));
expectType<Instance>(createSingleton(tippyInstances, {content: 'hello'}));
expectType<Instance>(createSingleton(tippyInstances, {overrides: ['content']}));

expectType<Instance>(
tippy(singleTarget, {
plugins: [animateFill, followCursor, inlinePositioning, sticky],
})
);

const customPlugin: Plugin = {
name: 'custom',
defaultValue: 42,
fn(instance) {
expectType<Instance>(instance);
return {};
},
};
expectType<Instance>(tippy(singleTarget, {plugins: [customPlugin]}));

expectType<void>(hideAll({duration: 50, exclude: tippy(singleTarget)}));

expectType<string>(roundArrow);
Loading

0 comments on commit 11c1836

Please sign in to comment.