-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
Presently it's possible for test behavior and real code behavior to differ because changes to objects returned by chrome.storage.local.get can be "persistently" modified in functions that do not save the result to chrome.storage.
interface Thing {
array: string[]
}
function saveThing(thing: Thing) {
return new Promise((resolve) => {
chrome.storage.local.set({ thing: thing }, () => {
resolve(true)
})
})
}
function getThing(): Promise<Thing> {
return new Promise((resolve) => {
chrome.storage.local.get('thing', (data: { thing: Thing }) => {
resolve(data.thing)
})
})
}
function doSomethingWithThing(thing: Thing) {
thing.array = thing.array.map((string) => {
return 'bar'
})
}
describe('Thing should work', () => {
it('thing works', async () => {
await saveThing({ array: ['foo'] })
let thing = await getThing()
expect(thing.array[0]).toEqual('foo')
doSomethingWithThing(thing)
thing = await getThing()
expect(thing.array[0]).toEqual('foo')
})
})
Expected: "foo"
Received: "bar"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels