Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Add some tests for Result
Browse files Browse the repository at this point in the history
  • Loading branch information
georg-schwarz committed May 9, 2022
1 parent b4afbdc commit 2c9b6cf
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Result.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { failure, success } from './Result';

describe('Success', () => {
it('should be a success', () => {
const s = success(123);
expect(s.isSuccess()).toBe(true);
});

it('should be no failure', () => {
const s = success(123);
expect(s.isFailure()).toBe(false);
});

it('should apply map', () => {
const s = success(123);
const mapped = s.map((x) => x > 5);
expect(mapped.isSuccess()).toBe(true);
expect(mapped.getUnsafe()).toBe(true);
});
});

describe('Failure', () => {
it('should be a failure', () => {
const f = failure('failure');
expect(f.isSuccess()).toBe(false);
});

it('should be no success', () => {
const f = failure('failure');
expect(f.isFailure()).toBe(true);
});

it('should apply map', () => {
const f = failure('failure');
const mapped = f.map(() => false);
expect(mapped.isSuccess()).toBe(false);
expect(() => {
mapped.getUnsafe();
}).toThrow(Error);
});
});

0 comments on commit 2c9b6cf

Please sign in to comment.