Files
privacy.sexy/tests/unit/infrastructure/SystemOperations/WindowInjectedSystemOperations.spec.ts
undergroundwires 949fac1a7c Refactor to enforce strictNullChecks
This commit applies `strictNullChecks` to the entire codebase to improve
maintainability and type safety. Key changes include:

- Remove some explicit null-checks where unnecessary.
- Add necessary null-checks.
- Refactor static factory functions for a more functional approach.
- Improve some test names and contexts for better debugging.
- Add unit tests for any additional logic introduced.
- Refactor `createPositionFromRegexFullMatch` to its own function as the
  logic is reused.
- Prefer `find` prefix on functions that may return `undefined` and
  `get` prefix for those that always return a value.
2023-11-12 22:54:00 +01:00

47 lines
1.8 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { getWindowInjectedSystemOperations } from '@/infrastructure/SystemOperations/WindowInjectedSystemOperations';
import { WindowVariables } from '@/infrastructure/WindowVariables/WindowVariables';
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
import { SystemOperationsStub } from '@tests/unit/shared/Stubs/SystemOperationsStub';
describe('WindowInjectedSystemOperations', () => {
describe('getWindowInjectedSystemOperations', () => {
describe('throws if window is absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing window';
const window: WindowVariables = absentValue as never;
// act
const act = () => getWindowInjectedSystemOperations(window);
// assert
expect(act).to.throw(expectedError);
}, { excludeUndefined: true });
});
describe('throw if system is absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing system';
const absentSystem = absentValue;
const window: Partial<WindowVariables> = {
system: absentSystem as never,
};
// act
const act = () => getWindowInjectedSystemOperations(window);
// assert
expect(act).to.throw(expectedError);
});
});
it('returns from window', () => {
// arrange
const expectedValue = new SystemOperationsStub();
const window: Partial<WindowVariables> = {
system: expectedValue,
};
// act
const actualValue = getWindowInjectedSystemOperations(window);
// assert
expect(actualValue).to.equal(expectedValue);
});
});
});