-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): debounce support multi instances
- Loading branch information
Netanel Basal
committed
Mar 14, 2019
1 parent
f203809
commit 2423fe2
Showing
18 changed files
with
6,616 additions
and
17,673 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.vscode | ||
node_modules | ||
.idea | ||
dist | ||
dist | ||
pkg |
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 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,43 +1,43 @@ | ||
import {debounce} from "../src"; | ||
import { debounce } from '../src'; | ||
|
||
jest.mock('lodash.debounce', () => { | ||
return (func, wait) => { | ||
let timeout; | ||
return function (this: any, ...args) { | ||
const context = this; | ||
clearTimeout(timeout); | ||
timeout = setTimeout(() => func.apply(context, args), wait); | ||
} | ||
return (func, wait) => { | ||
let timeout; | ||
return function(this: any, ...args) { | ||
const context = this; | ||
clearTimeout(timeout); | ||
timeout = setTimeout(() => func.apply(context, args), wait); | ||
}; | ||
}; | ||
}); | ||
|
||
jest.useFakeTimers(); | ||
|
||
class Test { | ||
id; | ||
id; | ||
|
||
constructor(id) { | ||
this.id = id; | ||
} | ||
constructor(id) { | ||
this.id = id; | ||
} | ||
|
||
@debounce(3000) | ||
method() { | ||
this.id++; | ||
} | ||
@debounce(3000) | ||
method() { | ||
this.id++; | ||
} | ||
} | ||
|
||
describe('Multi instance support', () => { | ||
describe('Debounce', () => { | ||
it('should work with multi instance', () => { | ||
const classA = new Test(1); | ||
const classB = new Test(100); | ||
classA.method(); | ||
jest.advanceTimersByTime(1000); | ||
classB.method(); | ||
jest.advanceTimersByTime(2001); | ||
expect(classA.id).toBe(2); | ||
jest.advanceTimersByTime(1000); | ||
expect(classB.id).toBe(101); | ||
}); | ||
describe('Debounce', () => { | ||
it('should work with multi instance', () => { | ||
const classA = new Test(1); | ||
const classB = new Test(100); | ||
classA.method(); | ||
jest.advanceTimersByTime(1000); | ||
classB.method(); | ||
jest.advanceTimersByTime(2001); | ||
expect(classA.id).toBe(2); | ||
jest.advanceTimersByTime(1000); | ||
expect(classB.id).toBe(101); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.