filter method for array state

This commit is contained in:
Niels Lyngsø
2023-01-25 09:59:24 +01:00
parent 043d2ec9a8
commit f7045e6718
2 changed files with 74 additions and 9 deletions

View File

@@ -33,12 +33,38 @@ describe('ArrayState', () => {
});
it('remove method, removes the one with the key', (done) => {
const expectedData = [initialData[0], initialData[2]];
subject.remove(['2']);
const observer = subject.asObservable();
observer.subscribe((value) => {
expect(JSON.stringify(value)).to.be.equal(JSON.stringify(expectedData));
done();
});
});
it('filter method, removes anything that is not true of the given predicate method', (done) => {
const expectedData = [initialData[0], initialData[2]];
subject.filter(x => x.key !== '2');
const observer = subject.asObservable();
observer.subscribe((value) => {
expect(JSON.stringify(value)).to.be.equal(JSON.stringify(expectedData));
done();
});
});
it('add new item via appendOne method.', (done) => {
const newItem = {key: '4', another: 'myValue4'};
subject.appendOne(newItem);
const expectedData = [...initialData, newItem]
const expectedData = [...initialData, newItem];
const observer = subject.asObservable();
observer.subscribe((value) => {