Skip to content

Commit

Permalink
Update IsNonNull tests
Browse files Browse the repository at this point in the history
  • Loading branch information
XanderVertegaal committed May 24, 2024
1 parent 7d4ab24 commit 7360b27
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions frontend/src/app/shared/operators/IsNonNull.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import { filterOutNonNull } from "./IsNonNull";
import { of } from "rxjs";

fdescribe('isNonNull', () => {
interface TestInterface {
myTest: 'always succeeds';
}

describe('isNonNull', () => {
it('should filter out null and undefined values', () => {
const source = of('hello', null, 123, undefined, true, {}, []);
const expected = ['hello', 123, true, {}, []];
const testObject = { key: 'value' };
const testArray = [1, 2, 3];
const source = of('hello', null, 123, undefined, true, testObject, testArray);
const expected = ['hello', 123, true, testArray, testObject];

source.pipe(filterOutNonNull()).subscribe((value) => {
expect(expected.includes(value)).toBe(true);
});
});

it('should return correctly typed data', () => {
const source = of('hello');

it('should return data of the correct type', () => {
function testFunction(input: TestInterface): void {
expect(input.myTest).toBe('always succeeds');
}
const input: TestInterface = { myTest: 'always succeeds' };
const source = of(null, input, undefined);
source.pipe(filterOutNonNull()).subscribe((value) => {
expect(typeof value).toBe('string');
expect(value).toBe('hello');
// This should not compile if null/undefined are allowed to pass through.
testFunction(value);
});
});
});

0 comments on commit 7360b27

Please sign in to comment.