Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for remaining actions #18

Merged
merged 1 commit into from Feb 5, 2021
Merged

Conversation

geoffrich
Copy link
Collaborator

Resolves #5

This adds tests for the remaining actions:

  • lazyload
  • longpress
  • pannable
  • preventTabClose
  • shortcut

It also adds cleanup to the existing clickOutside tests -- the nodes created for the test were not being removed from the DOM and the action wasn't being destroyed.

Writing these tests discovered a bug where the shortcut action was not updating params. This PR fixes that bug as well.

@geoffrich geoffrich requested a review from swyxio February 5, 2021 16:40
@geoffrich geoffrich self-assigned this Feb 5, 2021
@geoffrich
Copy link
Collaborator Author

Test output:

➜ npm test

> svelte-actions@0.1.0 test /home/grich/git/svelte-actions
> mocha ./src/test.ts



  clickOutside
    ✓ calls callback on outside click
    ✓ does not call callback when disabled
    ✓ does not call callback when element clicked
    ✓ updates parameters

  lazyload
    ✓ observes node
    ✓ sets attribute on intersection
    ✓ does not set attribute when no intersection

  longpress
    ✓ dispatches longpress event when mousedown more than duration
    ✓ does not dispatch longpress event when mousedown less than duration
    ✓ updates duration

  pannable
    ✓ dispatches pan events

  preventTabClose
    ✓ cancels beforeunload event when enabled
    ✓ does not cancel beforeunload event when disabled
    ✓ updates enabled parameter

  shortcut
    ✓ calls callback when callback provided
    ✓ clicks node when callback not provided
    ✓ does not call callback when different key pressed
    ✓ handles alt key
    ✓ handles shift key
    ✓ handles ctrl and meta key
    ✓ updates key code


  21 passing (52ms)

@swyxio
Copy link
Owner

swyxio commented Feb 5, 2021

this is beautiful!! am interested in adding github CI/CD on this next. will take a quick look

@swyxio swyxio merged commit 9bb2213 into swyxio:main Feb 5, 2021
@swyxio
Copy link
Owner

swyxio commented Feb 5, 2021

added here 65beaa1

@@ -3,5 +3,12 @@ import * as jsdom from 'jsdom';
const window = new jsdom.JSDOM('<main></main>').window;
global.document = window.document;
global.window = window;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type error:

Error: src/test.ts(5,1): error TS2322: Type 'DOMWindow' is not assignable to type 'Window & typeof globalThis'.
  Type 'DOMWindow' is not assignable to type 'Window'.
    Types of property 'self' are incompatible.
      Type 'DOMWindow' is not assignable to type 'Window & typeof globalThis'.
        Type 'DOMWindow' is missing the following properties from type 'typeof globalThis': RTCStatsReport, AnalyserNode, Animation, AnimationEffect, and 489 more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open a separate PR to fix these. Didn't realize they were build breaking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#20

window.dispatchEvent(event);

assert.ok(preventDefaultSpy.calledOnce);
assert.ok(returnValSpy.set.calledWith(''));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type error

Argument of type '""' is not assignable to parameter of type 'boolean | SinonMatcher | undefined'.ts(2345)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #20

@geoffrich geoffrich deleted the more-tests branch February 8, 2021 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TODO: add tests
2 participants