UNPKG

archunit

Version:

ArchUnit TypeScript is an architecture testing library, to specify and assert architecture rules in your TypeScript app

99 lines 4.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const result_factory_1 = require("../common/result-factory"); const violation_factory_1 = require("../common/violation-factory"); const jasmine_adapter_1 = require("./jasmine-adapter"); jest.mock('../common/result-factory'); jest.mock('../common/violation-factory'); describe('jasmineMatcher', () => { let mockResultFactory; let mockViolationFactory; beforeEach(() => { mockResultFactory = result_factory_1.ResultFactory; mockViolationFactory = violation_factory_1.ViolationFactory; jest.clearAllMocks(); }); describe('toPassAsync', () => { it('should return a matcher with a compare function', () => { const matcher = jasmine_adapter_1.jasmineMatcher.toPassAsync(); expect(matcher).toHaveProperty('compare'); expect(typeof matcher.compare).toBe('function'); }); it('should return failure when checkable is null', async () => { const matcher = jasmine_adapter_1.jasmineMatcher.toPassAsync(); const result = await matcher.compare(null); expect(result).toEqual({ pass: false, message: 'expected something checkable as an argument for expect()', }); }); it('should return failure when checkable is undefined', async () => { const matcher = jasmine_adapter_1.jasmineMatcher.toPassAsync(); const result = await matcher.compare(undefined); expect(result).toEqual({ pass: false, message: 'expected something checkable as an argument for expect()', }); }); it('should process violations and return result', async () => { const mockViolations = [{ type: 'test' }]; const mockCheckable = { check: jest.fn().mockResolvedValue(mockViolations), }; const mockProcessedViolation = { message: 'test', details: {} }; const mockResult = { pass: true, message: jest.fn().mockReturnValue('success'), }; mockViolationFactory.from.mockReturnValue(mockProcessedViolation); mockResultFactory.result.mockReturnValue(mockResult); const matcher = jasmine_adapter_1.jasmineMatcher.toPassAsync(); const result = await matcher.compare(mockCheckable); expect(mockCheckable.check).toHaveBeenCalled(); expect(mockViolationFactory.from).toHaveBeenCalledWith(mockViolations[0]); expect(mockResultFactory.result).toHaveBeenCalledWith(false, [ mockProcessedViolation, ]); expect(result.pass).toBe(true); expect(result.message).toBe('success'); }); it('should handle multiple violations', async () => { const mockViolations = [ { type: 'error1' }, { type: 'error2' }, ]; const mockCheckable = { check: jest.fn().mockResolvedValue(mockViolations), }; const mockProcessedViolations = [ { message: 'v1', details: {} }, { message: 'v2', details: {} }, ]; mockViolationFactory.from .mockReturnValueOnce(mockProcessedViolations[0]) .mockReturnValueOnce(mockProcessedViolations[1]); mockResultFactory.result.mockReturnValue({ pass: false, message: jest.fn().mockReturnValue('2 violations'), }); const matcher = jasmine_adapter_1.jasmineMatcher.toPassAsync(); await matcher.compare(mockCheckable); expect(mockViolationFactory.from).toHaveBeenCalledTimes(2); expect(mockResultFactory.result).toHaveBeenCalledWith(false, mockProcessedViolations); }); it('should pass CheckOptions to checkable.check', async () => { const options = { allowEmptyTests: true }; const mockCheckable = { check: jest.fn().mockResolvedValue([]), }; mockResultFactory.result.mockReturnValue({ pass: true, message: jest.fn().mockReturnValue('passed'), }); const matcher = jasmine_adapter_1.jasmineMatcher.toPassAsync(); await matcher.compare(mockCheckable, options); expect(mockCheckable.check).toHaveBeenCalledWith(options); }); }); }); //# sourceMappingURL=jasmine-adapter.spec.js.map