-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from g2crowd/tcarac/cleanup
refactor: remove jq dependency
- Loading branch information
Showing
9 changed files
with
79 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
16.15.0 | ||
20.9.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
nodejs 14.17.1 | ||
nodejs 20.9.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
import initiationStrategies from './initiationStrategies'; | ||
|
||
export const strategies = initiationStrategies({ | ||
nextTick(pluginFn, $$) { | ||
return window.setTimeout(() => pluginFn(), 0); | ||
}, | ||
|
||
immediate(pluginFn, $$) { | ||
return pluginFn() || {}; | ||
}, | ||
|
||
hover(pluginFn, $$) { | ||
return $$.one('mouseover', () => pluginFn()); | ||
} | ||
}); | ||
export function nextTick(pluginFn, _el) { | ||
return window.setTimeout(() => pluginFn(), 0); | ||
} | ||
export function immediate(pluginFn, _el) { | ||
return pluginFn() || {}; | ||
} | ||
export function hover(pluginFn, el) { | ||
const isJqueryEl = el.jquery !== undefined; | ||
return isJqueryEl ? | ||
el.one('mouseover', pluginFn) : | ||
el.addEventListener('mouseover', pluginFn, { once: true }); | ||
} | ||
export function fallback(strategy, fallback) { | ||
console.warn(`Strategy ${strategy} not found, falling back to ${fallback.name} strategy.`); | ||
return fallback; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
import * as strategies from '../src/strategies'; | ||
jest.useFakeTimers(); | ||
|
||
describe('strategies', () => { | ||
beforeEach(() => { | ||
jest.clearAllTimers(); | ||
}); | ||
describe('fallback', () => { | ||
it('should fall back to the provided strategy', () => { | ||
const fallback = strategies.fallback('nonexistent', strategies.nextTick); | ||
expect(fallback).toEqual(strategies.nextTick); | ||
}); | ||
|
||
it('should log a warning', () => { | ||
const nonexistentStrategy = 'nonexistent'; | ||
const fallbackStrategy = strategies.nextTick; | ||
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => { }); | ||
strategies.fallback(nonexistentStrategy, fallbackStrategy); | ||
expect(warnSpy).toHaveBeenCalledWith(`Strategy ${nonexistentStrategy} not found, falling back to ${fallbackStrategy.name} strategy.`); | ||
}); | ||
}) | ||
describe('nextTick', () => { | ||
it('should call the plugin function', () => { | ||
const pluginFn = jest.fn(); | ||
strategies.nextTick(pluginFn); | ||
jest.runAllTimers(); | ||
expect(pluginFn).toHaveBeenCalled(); | ||
}); | ||
}); | ||
describe('immediate', () => { | ||
it('should call the plugin function', () => { | ||
const pluginFn = jest.fn(); | ||
strategies.immediate(pluginFn); | ||
expect(pluginFn).toHaveBeenCalled(); | ||
}); | ||
}); | ||
describe('hover', () => { | ||
describe('with a jQuery element', () => { | ||
it('should call the plugin function', () => { | ||
const pluginFn = jest.fn(); | ||
const el = { jquery: true, one: jest.fn() }; | ||
strategies.hover(pluginFn, el); | ||
expect(el.one).toHaveBeenCalledWith('mouseover', pluginFn); | ||
}); | ||
}); | ||
describe('with a DOM element', () => { | ||
it('should call the plugin function', () => { | ||
const pluginFn = jest.fn(); | ||
const el = { addEventListener: jest.fn() }; | ||
strategies.hover(pluginFn, el); | ||
expect(el.addEventListener).toHaveBeenCalledWith('mouseover', pluginFn, { once: true }); | ||
}); | ||
}) | ||
}); | ||
}) |