Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should trigger a changed signal', () => {
let called = false;
const value = new ObservableMap();
value.changed.connect((sender, args) => {
expect(sender).to.equal(value);
expect(args.type).to.equal('add');
expect(args.newValue).to.equal(1);
expect(args.oldValue).to.be.undefined;
expect(args.key).to.equal('one');
called = true;
});
value.set('one', 1);
expect(called).to.equal(true);
});
});
it('should accept no arguments', () => {
const value = new ObservableMap();
expect(value instanceof ObservableMap).to.equal(true);
});
});
it('should be emitted when the map changes state', () => {
let called = false;
const value = new ObservableMap();
value.changed.connect(() => {
called = true;
});
value.set('entry', 1);
expect(called).to.equal(true);
});
it('should return the number of entries in the map', () => {
const value = new ObservableMap();
value.set('one', 1);
value.set('two', 2);
expect(value.size).to.equal(2);
});
});
it('should dispose of the resources held by the map', () => {
const value = new ObservableMap();
value.set('one', 1);
value.set('two', 2);
value.dispose();
expect(value.isDisposed).to.equal(true);
});
});
it('should remove all items from the map', () => {
const value = new ObservableMap();
value.set('one', 1);
value.set('two', 2);
value.set('three', 3);
value.clear();
expect(value.size).to.equal(0);
value.clear();
expect(value.size).to.equal(0);
});
it('should whether the key exists in a map', () => {
const value = new ObservableMap();
value.set('one', 1);
expect(value.has('one')).to.equal(true);
expect(value.has('two')).to.equal(false);
});
});
it('should test whether the map is disposed', () => {
const value = new ObservableMap();
expect(value.isDisposed).to.equal(false);
value.dispose();
expect(value.isDisposed).to.equal(true);
});
});
it('should return a list of the values in the map', () => {
const value = new ObservableMap();
value.set('one', 1);
value.set('two', 2);
value.set('three', 3);
const keys = value.values();
expect(keys).to.deep.equal([1, 2, 3]);
});
});
it('should trigger a changed signal', () => {
const value = new ObservableMap();
value.set('one', 1);
value.set('two', 2);
value.set('three', 3);
let called = false;
value.changed.connect((sender, args) => {
expect(sender).to.equal(value);
expect(args.type).to.equal('remove');
expect(args.key).to.equal('two');
expect(args.oldValue).to.equal(2);
expect(args.newValue).to.be.undefined;
called = true;
});
value.delete('two');
expect(called).to.equal(true);
});