-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix potential memory leak issue (#41)
- Loading branch information
1 parent
80910ae
commit 4924584
Showing
12 changed files
with
200 additions
and
122 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 |
---|---|---|
|
@@ -2,6 +2,10 @@ umd/* | |
dist/* | ||
es/* | ||
node_modules/* | ||
storybook-static/* | ||
private/* | ||
examples/* | ||
.vscode/* | ||
__stories__/* | ||
__tests__/* | ||
|
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
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,7 +1,54 @@ | ||
import { Data, removeData } from '../../lib/Data' | ||
import * as data from '../../lib/Data' | ||
|
||
const owner = document.createElement('div') | ||
|
||
afterEach(() => { | ||
data.remove(owner) | ||
}) | ||
|
||
describe(`Data(owner)`, () => { | ||
it(`Returns empty object when owner is undefined`, () => { | ||
expect(Data(undefined)).toEqual({}) | ||
it(`data.get(undefined) returns empty object`, () => { | ||
expect(data.get(undefined)).toEqual({}) | ||
}) | ||
it(`data.set(owner, key, value) works as expected`, () => { | ||
// Make sure data store is empty at start of test | ||
expect(data.cache).toEqual({}) | ||
data.set(owner, 'foo', 'bar') | ||
expect(data.cache[owner[data.expando]]).toEqual({ foo: 'bar' }) | ||
data.set(owner, 'hello', 'world') | ||
expect(data.cache[owner[data.expando]]).toEqual({ | ||
foo: 'bar', | ||
hello: 'world', | ||
}) | ||
}) | ||
it(`data.set(owner, objectMap) works as expected`, () => { | ||
// Make sure data store is empty at start of test | ||
expect(data.cache).toEqual({}) | ||
data.set(owner, { | ||
foo: 'bar', | ||
hello: 'world', | ||
}) | ||
expect(data.cache[owner[data.expando]]).toEqual({ | ||
foo: 'bar', | ||
hello: 'world', | ||
}) | ||
}) | ||
|
||
it(`data.get(owner) returns data object `, () => { | ||
// Make sure data store is empty at start of test | ||
expect(data.get(owner)).toEqual({}) | ||
// Set multiple properties by passing an object as the second arg | ||
data.set(owner, { | ||
foo: 'bar', | ||
hello: 'world', | ||
}) | ||
// Set an additional property using the (owner, key, value) syntax | ||
data.set(owner, 'other', 'value') | ||
// data.get(owner) should return an object with the the expected props | ||
expect(data.get(owner)).toEqual({ | ||
foo: 'bar', | ||
hello: 'world', | ||
other: 'value', | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.