-
Notifications
You must be signed in to change notification settings - Fork 0
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
7d4ab24
commit 7360b27
Showing
1 changed file
with
17 additions
and
8 deletions.
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
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); | ||
}); | ||
}); | ||
}); |