-
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.
- Loading branch information
1 parent
54e9a58
commit 5504f6d
Showing
2 changed files
with
94 additions
and
1 deletion.
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
79 changes: 79 additions & 0 deletions
79
src/collections/observableMap/tests/ObservableMap.delete.tests.ts
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,79 @@ | ||
import { ObservableMap } from '../ObservableMap'; | ||
import { testBlankMutatingOperation, testMutatingOperation } from './common'; | ||
|
||
describe('ObservableMap.delete', (): void => { | ||
it('deleting an item from an empty map returns false', (): void => { | ||
testBlankMutatingOperation<number, string>({ | ||
initialState: [], | ||
|
||
applyOperation: map => map.delete(1), | ||
|
||
expectedResult: false | ||
}); | ||
}); | ||
|
||
it('deleting an existing item removes it from the map and returns true', (): void => { | ||
testMutatingOperation<number, string>({ | ||
mapOperation: 'delete', | ||
initialState: [ | ||
[1, 'a'], | ||
[2, 'b'], | ||
[3, 'c'] | ||
], | ||
changedProperties: ['size'], | ||
|
||
applyOperation: map => map.delete(2), | ||
|
||
expectedMap: [ | ||
[1, 'a'], | ||
[3, 'c'] | ||
], | ||
expectedResult: true | ||
}); | ||
}); | ||
|
||
it('deleting an item that does not exist returns false', (): void => { | ||
testBlankMutatingOperation<number, string>({ | ||
initialState: [ | ||
[1, 'a'], | ||
[2, 'b'], | ||
[3, 'c'] | ||
], | ||
|
||
applyOperation: map => map.delete(4), | ||
|
||
expectedResult: false | ||
}); | ||
}); | ||
|
||
it('deleting items while iterating will break iterators', (): void => { | ||
expect( | ||
() => { | ||
const observableMap = new ObservableMap<number, string>([ | ||
[1, 'a'], | ||
[2, 'b'], | ||
[3, 'c'] | ||
]); | ||
|
||
for (const _ of observableMap) | ||
observableMap.delete(2); | ||
}) | ||
.toThrow(new Error('Map has changed while being iterated.')); | ||
}); | ||
|
||
it('deleting item that does not exist will not break iterators', (): void => { | ||
expect( | ||
() => { | ||
const observableMap = new ObservableMap<number, string>([ | ||
[1, 'a'], | ||
[2, 'b'], | ||
[3, 'c'] | ||
]); | ||
|
||
for (const _ of observableMap) | ||
observableMap.delete(4); | ||
}) | ||
.not | ||
.toThrow(); | ||
}); | ||
}); |